Search This Blog

Monday, September 6, 2010

how to parse a JSON string into JsonNode in Jackson?

Programmer Question

it should be so simple, but I just cannot find it after being trying for an hour #embarrasing



I need to get a JSON string e.g. {"k1":v1,"k2":v2} parsed as a JsonNode



  JsonFactory factory = new JsonFactory();

JsonParser jp = factory.createJsonParser("{\"k1\":\"v1\"}");

JsonNode actualObj = jp.readValueAsTree();


gives java.lang.IllegalStateException: No ObjectCodec defined for the parser, can not deserialize JSON into JsonNode tree



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails