I’ve read a bunch of different articles, comparations and tutorials that are using different JSON-Libraries for parsing (and creating) JSON into Java Objects. Anyway I think that I’ve got the facts right cause I’ve decided to use the JSON library called Jackson.
GSON is simple and robust but way to slow acording to me. So I decided to actually try this Jackson thing out but, it seems like the parsing is a little bit more confusing here than with GSON.
The data-type of the value that I want to parse is simply an Boolean.
This is what the JSON that I’m trying to parse looks like:
{"FooResult":true}
So what I actually need help with is selecting the value from the key FooResult and then parse its value into an Boolean.
This Is what I’ve done so far:
String json = getString(request);
ObjectMapper mapper = new ObjectMapper();
mapper.readValue(json, Boolean.class);
But this code obviously gives me an error cause I haven’t selected that it is the FooResult key that I’m interested in reading & parsing into an Boolean.
You should create a new class like this:
And use this code to load the data:
MyClass myObject = mapper.readValue(json, MyClass.class);Then you can access the value with
myObject.FooResult