Edison Edison - 1 month ago 9
JSON Question

Jackson read value as string

I have an object with unknown values, say

{
"data": [
{"a":...,
"dont_know_what_else_is_here":....}
]
}


And I just want to store the value of "data" as a string into a variable/database.

How should I read it from the streaming API?

Answer

Provided that you have already read this object into JsonNode, you can do it like this:

String content = jsonNode.get("data").textValue();

UPD: since you're using a streaming parser, this example on Jackson usage might help.

UPD: the method name is now textValue() - docs