-1

I'm trying to map two fields from Java POJO to one json field;

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
}

And I want to get response something like this:

{
    firstName: "Peter",
    address: {
        street: "Square nine",
        streetNumber: "12"
    }
}
micko
  • 1
  • Hi Micko. Welcome to SO community. In order to keep our community clean and avoid duplication of questions I can point you to the duplicated question that you have asked. https://stackoverflow.com/questions/15786129/converting-java-objects-to-json-with-jackson – nabster Apr 20 '20 at 23:11
  • Does this answer your question? [Converting Java objects to JSON with Jackson](https://stackoverflow.com/questions/15786129/converting-java-objects-to-json-with-jackson) – nabster Apr 20 '20 at 23:13

1 Answers1

0

You should implement then another POJO Address and add address field to your Person 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
}
Nowhere Man
  • 19,170
  • 9
  • 17
  • 42