Reputation: 512
Consider these classes:
public class A {
private String a;
private B b;
}
public class B {
private String b1;
private String b2;
}
Is there a way to serialize an object of A using Jackson, without using a custom serializer, so that the result is:
{"a":"aaa", "b1":"bbb1", "b2":"bbb2"}
?
Upvotes: 2
Views: 634
Reputation: 40078
You can simply use @JsonUnwrapped on field
Annotation used to indicate that a property should be serialized "unwrapped"; that is, if it would be serialized as JSON Object, its properties are instead included as properties of its containing Object.
public class A {
private String a;
@JsonUnwrapped
private B b;
}
public class B {
private String b1;
private String b2;
}
Upvotes: 1