You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by Mike Rheinheimer <ro...@apache.org> on 2009/10/07 20:22:50 UTC
Fwd: [jackson-user] A nifty new feature; JsonParser from JSON tree
(JsonNode)
Team, I'm subscribed to the Jackson mailing list, and try to keep up
with it. Tatu is one of the main developers over there. I just got
this email with an interesting new feature described. Basically,
Jackson now has data binding from JSON to Java objects without the
intermediate
JAXB introspector their default JAX-RS provider uses.
The reverse, however, is not yet available. It's in plan though: "So
going forward I am planning to add reverse too (JsonGenerator for
building JSON tree -> ability to serialize POJOs as JSON trees)."
Read below for more description if you're interested. Perhaps this is
a good reason to take another look at Jackson as a default JSON
provider?
mike
---------- Forwarded message ----------
From: Tatu Saloranta <ts...@gmail.com>
Date: Wed, Oct 7, 2009 at 1:49 AM
Subject: [jackson-user] A nifty new feature; JsonParser from JSON tree
(JsonNode)
To: user@jackson.codehaus.org
Here's something that I think will be very useful for lotsa things,
including semi-automated polymorphic deserialization (but more on that
point later on, first things first...).
I added functionality that allows constructing a JsonParser from a
JSON tree, like so:
ObjectMapper mapper = new ObjectMapper();
JsonNode tree = mapper.readTree("{ \"name\" : \"Woodstox\", \"stars\" : 5 }");
JsonParser jp = tree.traverse();
... so?
Well, given a JsonParser, one can do data binding, like:
Application app = mapper.readValue(jp, Application.class);
In other words, you can easily bind Objects from JSON trees. In fact,
ObjectMapper has a short cut:
Application app = mapper.treeToValue(tree, Application.class);
Still not sure why it matters? Keep in mind that you can use JsonNode
as a type to bind to/from with mapper, so that you could creator
method like:
@JsonCreator
static MyType construct(JsonNode treeOfData) {
}
and extract type from tree (String type =
treeOfData.remove("type").getTextValue();)...
and so on.
There is still the question of where to get an ObjectMapper, within
that factory method; but the basic idea should be quite simple.
Anyway: just thought I mention this in case it might give some useful ideas,
-+ Tatu +-
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email