Created
June 16, 2015 19:51
-
-
Save nzroller/5c500b1f1515786c3e58 to your computer and use it in GitHub Desktop.
Include.NON_EMPTY default and afterburner serialization test
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
import static org.junit.Assert.assertEquals; | |
import org.junit.Test; | |
import com.fasterxml.jackson.annotation.JsonInclude; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.module.afterburner.AfterburnerModule; | |
public class PrimitiveTest { | |
@JsonInclude(JsonInclude.Include.NON_EMPTY) | |
public static class NonEmptyIntWrapper { | |
private int value; | |
public NonEmptyIntWrapper(int v) { | |
value = v; | |
} | |
public int getValue() { | |
return value; | |
} | |
} | |
// [Issue#39] | |
@Test | |
public void testEmptyExclusion() throws Exception { | |
ObjectMapper mapper = mapperWithModule(); | |
String json; | |
json = mapper.writeValueAsString(new NonEmptyIntWrapper(3)); | |
assertEquals("{\"value\":3}", json); | |
json = mapper.writeValueAsString(new NonEmptyIntWrapper(0)); | |
assertEquals("{}", json); | |
mapper = new ObjectMapper(); | |
json = mapper.writeValueAsString(new NonEmptyIntWrapper(3)); | |
assertEquals("{\"value\":3}", json); | |
json = mapper.writeValueAsString(new NonEmptyIntWrapper(0)); | |
assertEquals("{}", json); | |
} | |
private ObjectMapper mapperWithModule() { | |
return new ObjectMapper().registerModule(new AfterburnerModule()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns
org.junit.ComparisonFailure: expected:<{[]}> but was:<{["value":0]}>
for the non-afterburner version.