Error while receiving ArrayList<Class> in WebService of Spring sent from Android App -


i want send arraylist class spring web service android app, receiving json kind of data should cast automatically arraylist in web service not doing that.

code android app

some.class

public serverresponse addselectedproducts(arraylist<totalselectedproduct> totalselectedproducts) {       gson gson = new gsonbuilder()             .setfieldnamingpolicy(fieldnamingpolicy.lower_case_with_underscores).create();      restadapter restadapter = new restadapter.builder()             .setendpoint("http://10.0.3.2:8082")             .setconverter(new gsonconverter(gson))             .build();     retrofitservice service = restadapter.create(retrofitservice.class);     try {         serverresponse serverresponse = service.addselectedproducts(totalselectedproducts);         log.i("imin:aproducts&i got",boolean.tostring(serverresponse.isadded()));         return serverresponse;     } catch (retrofiterror error) {         log.e("***error***",error.tostring());     }     serverresponse dr=new serverresponse();     dr.setadded(false);     return dr; } 

interface code

@headers({ "content-type: application/json" }) @post("/vendorwebapplication/addselectedproducts") public serverresponse addselectedproducts(@body arraylist<totalselectedproduct> totalselectedproducts); 

web service code

@requestmapping(value = "/addselectedproducts",method = requestmethod.post,consumes="application/json")     @responsebody      public serverresponse addselectedproducts(@requestbody arraylist<totalselectedproduct> totalselectedproducts){          system.out.println("imin:"+"addselectedproductsgotselected"+totalselectedproducts.tostring());          try{          int i=1;          while (i < totalselectedproducts.size()){               system.out.println("i:"+i);                 system.out.println("productid:"+string.valueof(totalselectedproducts.get(i).getproductid()));                 system.out.println("vendorid:"+totalselectedproducts.get(i).getvendorid());                 i++;                  }         }catch(exception e){             system.out.println("eee"+e.tostring());         }           return serverresponse;       } 

totalselectedproduct.class

public class totalselectedproduct {  @serializedname("vendorid") int vendorid; @serializedname("productid") int productid; @serializedname("description") string description;   public totalselectedproduct() {  }  public int getvendorid() {     return vendorid; }  public void setvendorid(int vendorid) {     this.vendorid = vendorid; }  public int getproductid() {     return productid; }  public void setproductid(int productid) {     this.productid = productid; }  public string getdescription() {     return description; }  public void setdescription(string description) {     this.description = description; } 

}

now console showing exception :

imin:addselectedproductsgotselected[{productid=2, vendorid=1}, {productid=3, vendorid=1}]

eeejava.lang.classcastexception: java.util.linkedhashmap cannot cast com.arsenal.vendorappserver.model.totalselectedproduct

here can see tostring() working showing json format not performing action when use arraylist<>

can 1 tell should add convert json arraylist<class> ?

after edit: beans convertor

<bean id="viewresolver"     class="org.springframework.web.servlet.view.urlbasedviewresolver">     <property name="viewclass"         value="org.springframework.web.servlet.view.jstlview" />     <property name="prefix" value="/web-inf/jsp/" />     <property name="suffix" value=".jsp" /> </bean>  <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter">     <property name="messageconverters">         <list>             <ref bean="jsonconverter" />         </list>     </property> </bean>  <bean id="jsonconverter" class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter">     <property name="supportedmediatypes" value="application/json"></property> </bean> 


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -