public static void main(String[] args) throws Exception {
var example = new NameContainer("Ivanov", "Petr");
var objectMapper = new ObjectMapper();
var json = objectMapper.writeValueAsString(example);
System.out.println(json); // {"firstName":"Ivanov","lastName":"Petr","fullName":"Ivanov Petr"}
}
record NameContainer(String firstName, String lastName) {
@JsonProperty("fullName")
String getFullName() {
return firstName + " " + lastName;
}
}
public static void main(String[] args) throws Exception {
var example = new Example(1, 2);
System.out.println(example.getAPlusB());
}
record Example(Integer a, Integer b) {
Integer getAPlusB() {
return a + b;
}
}