We're having problems figuring out how to configure jackson to match how
we'd like to have things. We have a bunch of legacy java classes (that we
cannot annotate) that we'd like de-serialize from json. We have something
similar to the following structure.
interface Animal { ... }
interface Dog implements Animal { ... }
class DogImpl implements Dog { ... }
interface Cat implements Animal { ... }
class CatImpl implements Cat { ... }
class Zoo {
List<Animal> animals;
String zooName;
}
Preferably we'd like to see jackson understand and convert the following
json
{
"zooName": "Carl's Zoo",
"animals": [
{ "@class": "com.acme.zoo.DogImpl", ... },
{ "@class": "com.acme.zoo.DogImpl", ... },
{ "@class": "com.acme.zoo.CatImpl", ... },
]
}
But we also like to be able to send Lists as root objects, like:
[
{ "@class": "com.acme.zoo.DogImpl", ... },
{ "@class": "com.acme.zoo.DogImpl", ... },
{ "@class": "com.acme.zoo.CatImpl", ... },
]
Our current approach is to have a SimpleModule that
uses addAbstractTypeMapping between Dog/Cat and DogImpl/CatImpl.
And addValueInstantiator to add custom instatiators for CatImpl/DogImpl,
because we need to use factories to create the legacy classes.
And we add type info with As.PROPERTY, but none of the different
DefaultTyping seems to give us the desired result. The whole thing is then
hooked into Spring via a Converter to map jackson to expected target class
(using objectMapper.readValue(.., targetClass)).
Is the above behavior something that jackson can be configured for? Or do
we have to implement some custom things and hook into jackson, if so, what
would that be? We're running jackson v. 2.5.1 at the moment (it was used in
another part of the product).
--
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.