Reputation: 2308
I have two java classes A and B that I would like to be able to serialize to JSON such that their content looks the same to a consumer.
I ommitted the constructors/getters/setters to keep it minimal.
public class A {
@JsonProperty("b")
private B b;
}
public class B {
@JsonProperty("propertyB")
public String propertyB;
}
When I serialize A I get
{
b: {
propertyB: ''
}
}
But I want it to look like B's serialization:
{
propertyB: ''
}
Is there any way to achieve that simply by configuring the serialization process respectively, i.e. using jackson annotations or some other form of jackson configuration.
Thanks
Upvotes: 0
Views: 47
Reputation: 14731
You can use @JsonUnwrapped
public class A {
@JsonUnwrapped
private B b;
}
Upvotes: 1