1
votes

I have a JSON format of

var array1 = new Array;
var array2 = new Array;
//push some string to array1 and array2
var data = JSON.stringify({'email':email,'age':age,'array1':array1,'array2':array2});

How could I map it to POJOs using Jackson JSON Mapper to avoid 400 Bad Request.

I have tried

public class MyPOJOs{
  private String email;
  private String age;
  private MyList array1;
  private MyList array2;
  //getters and setters
}
public class MyList{
  private ArrayList  list;
  //getter and setter
}

My controller

public @ResponseBody Response myController(@RequestBody MyPOJOs myPOJOs){
   String email = myPOJOs.getEmail();
   logger.log("Hi " + email);
   return null;
}

Thanks.

1
JSON requires using double quotes, not single.Kraylog
JSON.stringify is to convert JavaScript values to JSON, single quote is valid in JavaScript values, so I do not think the quotes matters in this case.user200340
Please add an actual example of the JSON string in data to your question. Also, how does it not work? Are there any exceptions? If so add them to your question in full.Philipp Reichart
Thanks, Philipp. The problem is sovled after defining "private ArrayList <String> array1; private ArrayList <String> array2;" in MyPOJOs class. The actual JSON data is very large,so I can not put them here.user200340

1 Answers

1
votes

I do not really know Jackson JSON processor but I would be surprised that it is able to map your arrays to your custom MyList objects.

I would expect the MyPOJOs class to have member like private String[] array1 or private List<String> array1 or a Collection.

btw: There are many mistakes in your code that make me think you do not post real code here. Misspelled type names etc.