forked from realjenius/jackson-databind-java8
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added another test to find interopability issues with AfterBurner as …
…noted in issue #2
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
src/test/java/org/zapodot/jackson/java8/AfterBurnerInteroperabilityTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.zapodot.jackson.java8; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.module.afterburner.AfterburnerModule; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author zapodot | ||
*/ | ||
public class AfterBurnerInteroperabilityTest { | ||
|
||
private ObjectMapper objectMapper; | ||
|
||
public static class Bean { | ||
|
||
public static final String PRESENT_VALUE = "present"; | ||
@JsonProperty | ||
private Optional<String> empty = Optional.empty(); | ||
|
||
@JsonProperty | ||
private Optional<String> notSet; | ||
|
||
@JsonProperty | ||
private Optional<String> present = Optional.of(PRESENT_VALUE); | ||
|
||
|
||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new AfterburnerModule()); | ||
objectMapper.registerModule(new JavaOptionalModule()); | ||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
} | ||
|
||
@Test | ||
public void testOptionalsWithAfterBurner() throws Exception { | ||
final String json = objectMapper.writeValueAsString(new Bean()); | ||
assertEquals("{\"present\":\"present\"}", json); | ||
final Bean bean = objectMapper.readValue(json, Bean.class); | ||
|
||
assertFalse(bean.empty.isPresent()); | ||
assertTrue(bean.present.isPresent()); | ||
assertNull(bean.notSet); | ||
|
||
} | ||
} |