Last active
May 9, 2018 06:04
-
-
Save ihoneymon/8fa579f8497caeb899127601e3effcd3 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* ObjectMapper 단위테스트 | |
*/ | |
@Slf4j | |
public class ObjectMapperTest { | |
private ObjectMapper objectMapper; | |
@Before | |
public void setUp() throws Exception { | |
objectMapper = new ObjectMapper(); | |
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | |
} | |
@Test | |
public void testSourceObject() throws JsonProcessingException { | |
Message source = Message.builder().subject("Test subject").body("Test body").build(); | |
log.debug("Result: {}", objectMapper.convertValue(source, Map.class)); | |
log.debug("Result: {}", objectMapper.writeValueAsString(source)); | |
} | |
@Getter | |
@Builder | |
public static class Message { | |
/** | |
* static 필드인 경우 ObjectMapper 가 변환에서 제외하는군! | |
*/ | |
private final static String DEFAULT_FIELD = "test"; | |
private String subject; | |
private String body; | |
private String description = DEFAULT_FIELD; | |
@JsonIgnore | |
private String ignoredField = "ignored"; | |
} | |
//11:16:11.375 [main] DEBUG ObjectMapperTest - Result: {subject=Test subject, body=Test body} | |
//11:16:11.382 [main] DEBUG ObjectMapperTest - Result: {"subject":"Test subject","body":"Test body"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment