Created
November 2, 2016 13:45
-
-
Save dehora/5caef12363ce643bbd2c312b6319804b to your computer and use it in GitHub Desktop.
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
package org.zalando.fahrschein.domain; | |
import com.fasterxml.jackson.annotation.JsonInclude; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.io.ByteArrayOutputStream; | |
import java.util.Collections; | |
import org.junit.Test; | |
import static org.junit.Assert.assertFalse; | |
public class SubscriptionTest { | |
@Test | |
public void serializationFailsUnlessFieldsAreMarkedIgnorable() throws Exception { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
// emulates NakadiClient#subscribe | |
final Subscription subscription = new Subscription("ss", Collections.singleton("s"), "cg"); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
objectMapper.writeValue(baos, subscription); | |
// bare object mappers serialize nulls | |
assertFalse(baos.toString().contains("id")); | |
assertFalse(baos.toString().contains("createdAt")); | |
} | |
@Test | |
public void passesWithConfiguredObjectMapper() throws Exception { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | |
// emulates NakadiClient#subscribe | |
final Subscription subscription = new Subscription("ss", Collections.singleton("s"), "cg"); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
objectMapper.writeValue(baos, subscription); | |
// nulls elided | |
assertFalse(baos.toString().contains("id")); | |
assertFalse(baos.toString().contains("createdAt")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the sub object is changed to use ignorables (see
// mark
below), the bare object mapper will pass