I want to use Jackson to create simple JSON objects, where I do not need to create custom classes for each response, but rather a ready-made object, similar to the code below. Other JSON libraries (android, JSON.org, GSON) you can do something similar to this
JsonObject myObject = new JsonObject("{\"a\":1}"); myObject.getInt("a");
I cannot find a similar operation in Jackson packages. PS : I know that I can create a java class to encapsulate this particular JSON string, but what I'm looking for is a way to create shared JSON objects that I DO NOT need to parse in the classes that I defined, It seems I can't find something on the internet that points me to something like this. I have a feeling that this is outside the Jackson zone, and they do not support such operations. If so, just say it and I will close the question.
My goal is not to have another Json library in my project.
Edit 2014:. I found that you can use the org.codehaus.jackson.node.ObjectNode class, which will contain your object and allow you to perform operations as described in my question.
Here is a sample code:
ObjectMapper mapper = new ObjectMapper(); ObjectNode myObject = (ObjectNode) mapper.readTree("{\"a\":1}"); System.out.println(myObject.get("a").asInt());
source share