JsonUnwrapped annotation behaves differently with gson and fasterxml objectmapper

40 views Asked by At

In my java project i am using XMLMapper to unwrap XML and get the output as json

Input XML:

<root>
<name>testName</name>
<town>testCity</town>
</root>

Java code

public class TestClass {
 @JsonAlias("name")
 private String name;
 @JsonUnwrapped
 private Address address;
}

public class Address {
 @JsonAlias("town")
 private String city;
}
 

When serialised

Gson produces below output

{
 "name":"testName",
 "address":{
 "city":"testCity"
 }
}

While objectmapper produces

{
 "name":"testName",
 "city":"testCity"
}

Is there any objectmapper option that i can get gson like output?

GSON version: 2.10.1 Fasterxml version : 2.14.0

0

There are 0 answers