This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Description
Consider the example:
public class Test {
public static void main(String[] args) throws JsonProcessingException {
System.out.println(new ObjectMapper()
.registerModule(new GuavaModule())
.writeValueAsString(new Parent()));
}
}
class Child {
@JsonProperty
private String text = "hello, world!";
}
class Parent {
@JsonProperty
@JsonUnwrapped
private Child child = new Child();
}
Produces: {"text":"hello, world!"}
Whereas the following example:
public class Test {
public static void main(String[] args) throws JsonProcessingException {
System.out.println(new ObjectMapper()
.registerModule(new GuavaModule())
.writeValueAsString(new Parent()));
}
}
class Child {
@JsonProperty
private String text = "hello, world!";
}
class Parent {
@JsonProperty
@JsonUnwrapped
private Optional<Child> child = Optional.of(new Child());
}
(note, that the child
field is now Optional)
Produces: {"child":{"text":"hello, world!"}}
Such a behaviour looks a bit odd and counterintuitive. In my opinion, the output should be the same as in the first case.