Hi I am trying to deserialize the json data using jackson in java. I am facing an error as follows:Unexpected token (START_ARRAY), expected VALUE_STRING: need JSON String that contains type id (for subtype of Attachment) Here is the code I have used. Please let me know how to resolve this issue. Thanks in advance.
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
Audio audio = new Audio(2,2,"www.google.com","HelloWorld");
List<Link1> link = new ArrayList<Link1>();
link.add(audio);
try {
String jsonDataString= mapper.writerWithDefaultPrettyPrinter().writeValueAsString(link);
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(link));
Attachment f1 = new Attachment();
f1 = mapper.readValue(jsonDataString,Attachment.class);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSON:
[[
"Audio",
{
"url" : "www.google.com",
"title" : "HelloWorld",
"aid" : 2,
"owner_id" : 2
}
]]