java - How can I receive multiple parameter values and return data in JSON format in Spring REST? -


i new spring , using spring mvc4. must receive requests, read multiple parameters in requests , apply business logic based on parameters , return data in json format.

testcontroller.java:

@requestmapping(value="/receiveupdatedstressscore",params = { "value", "device_model"},method=requestmethod.get, produces={"application/json"}) public string receiveupdatedstressscore(@requestparam(value="value")  int value,@requestparam(value="device_model") string device_model) {       return "here: "+value+" device_model "+device_model; } 

url: http://localhost:8080/appname/receiveupdatedstressscore?value=100&device_model=nokia

but i'm getting output not in json. output in browser is..

here: 100 device_model nokia

how convert json?

you returning string not auto-convert json. (note @responsebody , make sure have jackson dependency):

 @requestmapping(value="/receiveupdatedstressscore") public @responsebody device receiveupdatedstressscore(@requestparam(value="value") int value,@requestparam(value="device_model") string devicemodel)  {      device device = new device();     device.setdevicemodel(devicemodel);     device.setvalue(value);     return device;  }  public class device {     int value;     string devicemodel;     public int getvalue() {         return value;     }     public void setvalue(int value) {         this.value = value;     }     public string getdevicemodel() {         return devicemodel;     }     public void setdevicemodel(string devicemodel) {         this.devicemodel = devicemodel;     }  } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -