Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Jackson注释将multiiple Java pojo字段映射到一个json字段_Java_Json_Mapping_Jsonresponse - Fatal编程技术网

使用Jackson注释将multiiple Java pojo字段映射到一个json字段

使用Jackson注释将multiiple Java pojo字段映射到一个json字段,java,json,mapping,jsonresponse,Java,Json,Mapping,Jsonresponse,我试图将两个字段从JavaPOJO映射到一个json字段 public class Person { private String firstName; //this two fields should be in separate json property (object) private String street; private String streetNo; ... //getters and setters } 我想得到这样的回应: {

我试图将两个字段从JavaPOJO映射到一个json字段

public class Person {
    private String firstName;

    //this two fields should be in separate json property (object)
    private String street;
    private String streetNo;
...
    //getters and setters
}
我想得到这样的回应:

{
    firstName: "Peter",
    address: {
        street: "Square nine",
        streetNumber: "12"
    }
}

然后,您应该实现另一个POJO地址,并将
地址
字段添加到您的个人POJO中

public class Person {
    private String firstName;

    private Address address = new Address();

...
    //getters and setters
}

// another POJO
public class Address {
    private String street;
    private String streetNo;

    //getters and setters
}

嗨,米科。欢迎来到SO社区。为了保持社区清洁,避免问题重复,我可以向您指出您提出的重复问题。这回答了你的问题吗?