Hi,
I was trying to find a solution to let jackson to serialize without an
extra super type element.
I have a class that has an instance of a super type
A.java
{
SuperType superType;
// other object definitions
...
}
I also define a list of sub types extending the SuperType like;
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include =
JsonTypeInfo.As.WRAPPER_OBJECT ) // I tried PROPERTY, EXISTING_PROPERTY
etc.
@JsonSubTypes({
@JsonSubTypes.Type( name = "file", value = FileType.class ),
@JsonSubTypes.Type( name = "audio", value = AudioType.class )
})
public class SuperType
Now, when I construct A.java, the variable superType is assigned to
concrete type such as FileType or AudioType on run-time. By default, the
serialized json output will be
{ "superType":{ "file":{... a list of file attribute } } } or {"superType"
: { "audio": { ... a list of audio attribute } } }
I could change the type info definition to "EXISTING_PROPERTY", and I can
get the following output:
{"superType":{ .. a list of file attribute} } or {"superType":{ .. a list
of audio attribute} }
What I really want is:
{"file": { a list of file attribute } } or {"audio": { a list of audio
attribute} }
The only difference is the out layer element ("superType") is removed.
Note, I do not want additional type information or class information in the
output either.
It looks like I could not get rid of the element superType. I tried to
write a custom serializer. However, it would have to be applied on the
enclosing class ( A.java), and not on SuperType itself. This means a
complete custom serialization by hand coding.
Is there anyway to allow jackson to do it automatically.
Thanks,
Wayne
--
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.