Skip to content

Instantly share code, notes, and snippets.

@odrotbohm
Created June 29, 2020 21:08
Show Gist options
  • Save odrotbohm/125d15ec154a1ac72f74754ef1b03764 to your computer and use it in GitHub Desktop.
Save odrotbohm/125d15ec154a1ac72f74754ef1b03764 to your computer and use it in GitHub Desktop.
Jackson deserialization into a complex constructor
@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