Skip to content

Instantly share code, notes, and snippets.

@cherniag
Created October 29, 2019 13:31
Show Gist options
  • Save cherniag/cc58a865e1c4fe1092c41ffe2d3cd46e to your computer and use it in GitHub Desktop.
Save cherniag/cc58a865e1c4fe1092c41ffe2d3cd46e to your computer and use it in GitHub Desktop.
Jackson @JsonUnwrapped with Lombok @builder deserialization
@Value
@Builder
public class Parent {
long oneField;
@JsonProperty(access = JsonProperty.Access.READ_ONLY) // does magic - jackson will not set
@NonNull
@JsonUnwrapped
Child child;
@JsonCreator
public Parent(@JsonProperty("oneField") long oneField,
@JsonProperty("id") long id,
@JsonProperty("name") long name) {
this(oneField, new Child(id, name));
}
private Parent(long oneField, @NonNull Child child) {
this.oneField = oneField;
this.child = child;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment