我要序列化以下形式的pojo:
public class Person
{
private String firstName;
private String lastName;
private Map<String, String> details;
}
我正在使用地图,因为我没有很多额外的细节。 因此,例如,如果我将类实例化为:
Map<String, String> details = new HashMap<>();
details.put("age", "20");
details.put("favouriteAnimal", "Unicorn");
Person person = new Person("A", "B", details);
我希望json序列化看起来像:
{
"person": {
"firstName": "A",
"lastName": "B",
"age": "20,
"favouriteAnimal": "Unicorn"
}
}
使用Jackson,“默认”序列化格式为:
{
"person": {
"firstName": "A",
"lastName": "B",
"details": {
"age": "20",
"favouriteAnimal": "Unicorn"
}
}
}