I am trying to do this [see below], and it is throwing error.
1String x="{'candidateId':'k','candEducationId':1,'activitiesSocieties':'Activities for cand1'}"; 2ObjectMapper mapper = new ObjectMapper(); 3 4try { 5 JsonNode df=mapper.readValue(x,JsonNode.class); 6 int i=0; 7} catch .....
Exception:
1org.codehaus.jackson.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name 2at [Source: java.io.StringReader@1afd1810; line: 1, column: 3] 3 at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1291)
Solution:
It's not valid JSON, but you can tell Jackson to allow it. Here's how.
1String x = "{'candidateId':'k','candEducationId':1,'activitiesSocieties':'Activities for cand1'}"; 2ObjectMapper mapper = new ObjectMapper(); 3mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); 4JsonNode df = mapper.readValue(x, JsonNode.class); 5System.out.println(df.toString()); 6// output: {"candidateId":"k","candEducationId":1,"activitiesSocieties":"Activities for cand1"}