jackson v1.9.13 spring 3.2.0 Hi, I've been spending days trying to figure out how to add a field into a JSON from a bean during serialization.
It seems like a very basic feature but I bumped into rubber walls every route I took.
What I want to achieve:
example bean:
package org.mydomain;
public class MyBean implements Serializable {
private String foo;
public void setFoo( String inValue ) {
foo = inValue;
}
public String getFoo() {
return foo;
}
}
output:
{
"_type" : "org.mydomain.MyBean",
"foo" : "bar"
}
I reckon that the simples way would be to extend a BeanSerializer write the "_type" property and delegate the super class serialization of the remaining fields. Problem is, the accessibility of methods and the "final" clause of some crucial methods makes it a quagmire.
I tried extending BeanSerializerBase, JsonSerializer, BeanSerializerModifier.
Every time I crash into some impenetrable 24-arguments-constructor or some non/mis-documented method.
Very frustrating.
Anyone has any idea on how to achieve the above bit?
I'm using spring-mvc, therefore I need a pluggable solution via ObjectMapper configuration. I don't want to pollute my model or controller objects with json specific annotation or serialization logic.
Thanks a lot.
N.