Say I have bean classes defined thus:
public class Top {
public List<Bottom> bottoms;
}
public class Bottom {
public String foo;
}
And serialized form:
{
"bottoms" = [ {"foo" = "1"}, {"foo" = "2"} ]
}
The ObjectMapper will figure out that it needs to construct Bottom objects
to place into the bottoms property. But, how? I'm browsing the ObjectReader
code, looking at CollectionDeserializer, but I'm getting lost in the
details of the implementation. How does it ultimately figure out the value
deserializer?
Some background that probably isn't required, but in case someone is
interested. I'm trying to write a module that will, if a property name
isn't found, it will look for a method to call, passing it the deserialized
array or object. Also, if it's an array and the method takes a singleton
object, call the method multiple times. If the method takes a collection,
pass it directly, much like a normal setter.
I'm trying to keep the JSON as clean as possible, but I may end up doing
something like
{"@class": "<fully qualified name>"}
if I need to. I'm also trying to keep the bean classes totally agnostic to
this process, providing only the method needed.
I would mostly use this for Hibernate entity classes that need an "add"
method to keep one-to-many type relationships in sync. But, I can imagine
some more general uses of this as well.
So:
public class Top {
public List<Bottom> bottoms;
public void addBottom(Bottom bottom) {
bottoms.add(bottom);
bottom.top = this;
}
}
public class Bottom {
public String fool
public Top top;
}
and JSON something like:
{ "@addBottom" : [ {"foo" = "1"}, {"foo" = "2"} ] }
I understand the pitfalls and language limitations involved, so If I can't
achieve this level transparency, I'll punt and add more metadata to JSON.
Also, if anyone has done this before/better, I'd be interested, but I
haven't found anything like this in my searching.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.