0

I'm passing json array from angularjs, and it's comes on Spring Controller, I catch it there at @RequestBody String data

I want to store those data inside List,

I tried this,

List<RegisterDTO> stdList = JsonConvert.DeserializeObject<RegisterDTO>(data);

But I don't know JsonConvert from where it's coming? I'm getting an error there(cannot to be resolved).

RegisterController.java

@ResponseBody
@RequestMapping(value = "/registerStudent.do", method = RequestMethod.POST)
public boolean registerStudent(@RequestBody String data) {
    System.out.println(data);
    if (stdList != null) {
        // store stdList
    }
    return registerService.isStudentExist(stdList);

}
Elydasian
  • 2,016
  • 5
  • 23
  • 41
  • Possible duplicate of [java code corresponding to Newtonsoft.Json.JsonConvert.SerializeObject(Object source,Newtonsoft.Json.JsonSerializerSettings()) in .net?](http://stackoverflow.com/questions/5622049/java-code-corresponding-to-newtonsoft-json-jsonconvert-serializeobjectobject-so) –  Nov 03 '16 at 17:08
  • it's in .net.?..... i'm using java. so, what should i use ? –  Nov 03 '16 at 17:15
  • That is exactly what the dup asks: What is Java's equivalent of JsonConvert? –  Nov 03 '16 at 17:16

1 Answers1

0

So What you have provided is example of Newtonsoft JSON.net used for c#

For Java you have to use different libraries.

Like GSON

Here is an example on How to deserialize json string into object in JAVA

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28