I'm creating a microservice on Micronaut using Jackson.
However, I didn't find how it is possible to nest some properties inside the json without creating a separate class?
Entity JPA Class looks like this:
@Entity
@Table(name = "citizens", schema = "main")
@Introspected
public class Citizen {
@Id
@Column(name = "oid", nullable = false)
@JsonView(JsonViewSimple.class)
private String id;
@JsonInclude
@Column(name = "first_name")
@JsonSerialize(using = WhiteSpaceRemovalSerializer.class)
@JsonView(JsonViewSimple.class)
private String firstName;
@JsonInclude
@Column(name = "last_name")
@JsonSerialize(using = WhiteSpaceRemovalSerializer.class)
@JsonView(JsonViewSimple.class)
private String lastName;
..
JSON result:
{
"id": "123",
"first_name": "John",
"last_name": "Wick"
}
As a result,
I want to get first_name and last_name grouped into a json object name
{
"id": "123",
"name: {
"first_name": "John",
"last_name": "Wick"
}
}
What is the easiest way to do this without resorting to creating a separate child class and many lines of code?