Created
June 29, 2020 21:08
-
-
Save odrotbohm/125d15ec154a1ac72f74754ef1b03764 to your computer and use it in GitHub Desktop.
Jackson deserialization into a complex constructor
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
@SpringBootTest | |
@RequiredArgsConstructor | |
class Sample { | |
private final ObjectMapper jackson; | |
@Test | |
void deserializesThroughConstructor() throws Exception { | |
var result = jackson.readValue("{\"firstname\" : \"Dave\", \"lastname\" : \"Matthews\" }", SomeSample.class); | |
assertThat(result.getFirstname()).isEqualTo("Dave"); | |
assertThat(result.getLastname()).isEqualTo("Matthews"); | |
} | |
@Value | |
static class SomeSample { | |
String firstname, lastname; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment