I have an ArrayList<Person> that contains a few Person type objects. The Person class has the following attributes with their getters and setters:
private int id;
private String name;
private String email;
private LocalDate birthDate;
I'd like to export the ArrayList<Person> to a JSON output file with the exact same format:
persons.json:
[
{
"id": 1,
"name": "The Best",
"email": "thenextbigthing@gmail.com",
"birthDate": "1981-11-23"
},
{
"id": 2,
"name": "Andy Jr.",
"email": "usa@gmail.com",
"birthDate": "1982-12-01"
},
{
"id": 3,
"name": "JohnDoe",
"email": "gameover@gmail.com",
"birthDate": "1990-01-02"
},
{
"id": 4,
"name": "SomeOne",
"email": "rucksack@gmail.com",
"birthDate": "1988-01-22"
},
{
"id": 5,
"name": "Mr. Mxyzptlk",
"email": "bigman@hotmail.com",
"birthDate": "1977-08-12"
}
]
I've tried to create an Array from the ArrayList and create the output from that Array but I have a problem with that which I cannot work it around. I'm getting output data for the birthDate attribute looking like this:
"birthDate" : {
"year" : 1952,
"month" : "JANUARY",
"chronology" : {
"id" : "ISO",
"calendarType" : "iso8601"
},
"era" : "CE",
"leapYear" : true,
"dayOfMonth" : 27,
"monthValue" : 1,
"dayOfWeek" : "SUNDAY",
"dayOfYear" : 27
}
How can I make every attribute have the same output format as provided in the example persons.json output file. I'm not allowed to use any other Jackson library besides core, annotations and databind. I'm also not allowed to change attribute type inside the class.