Skip to content

Commit

Permalink
Added another test to find interopability issues with AfterBurner as …
Browse files Browse the repository at this point in the history
…noted in issue #2
  • Loading branch information
zapodot committed Jan 22, 2015
1 parent 1019cb3 commit bdd442b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</license>
</licenses>
<properties>
<junit.version>4.11</junit.version>
<junit.version>4.12</junit.version>
<jackson-core.version>2.4.4</jackson-core.version>
<jackson-databind.version>${jackson-core.version}</jackson-databind.version>
</properties>
Expand All @@ -61,6 +61,12 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>${jackson-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
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);

}
}

0 comments on commit bdd442b

Please sign in to comment.