0

I am trying to pass data from javascript to spring controller using jquery ajax.

var inputParam = {
  name: "xxx",
  address: {
    city: "chicago",
    zip: "123456"
  }
};

var jqxhr = $.ajax({
  url: "/myurl"+ $.param(inputparam),
  type: "GET",
  dataType: "html"               
});

controller

@RequestMapping(value = "/myurl", method = RequestMethod.GET)
 public String getMyPage(  @ModelAttribute InputParams inputParam,HttpServletRequest request, Model model ) throws Exception{
        //my code
  }

pojo

class InputParams  
{
  private String name;
  private Address address;
  //getter setter
}

class Address 
{
  private String city;
  private String zip;
  //getter setter
}

But this is not working and i am getting error

org.springframework.beans.InvalidPropertyException: Invalid property 'address[city]' of bean class [InputParams ]: Property referenced in indexed property path 'address[city]' is neither an array nor a List nor a Map; returned value was [City]

user9735824
  • 1,196
  • 5
  • 19
  • 36

0 Answers0