I have an input JSON which has fields what I sure inside. But, I need a flexibility to add several extra fields. I don't know the name of the extra fields, but I have to handle it.
I was thinking adding a MaP field which contains all of extra fields, but the inputs are not mapped into this field.
I want to deserialize the JSON in a Dropwizard endpoint.
Is there a way to do with Jackson?
Example:
JSON payload 1:
{
"first_name": "John",
"last_name": "Doe",
"date_of_birth": "01/01/1990",
"postcode": "1234"
}
JSON payload 2:
{
"first_name": "Alice",
"last_name": "Havee",
"phone_no": 012345678,
"passport_no": "AB 123456"
}
Later on JSON payload 3 can have even different fields.
Java DTO:
public class PersonDTO {
// mandatory field
private String firstName;
// mandatory field
private String lastName;
// Unknown optional fields?
// No args constructor
// Getters
// Setters
}