Created
October 29, 2019 13:31
-
-
Save cherniag/cc58a865e1c4fe1092c41ffe2d3cd46e to your computer and use it in GitHub Desktop.
Jackson @JsonUnwrapped with Lombok @builder deserialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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