Search in sources :

Example 1 with Containers

use of net.morimekta.test.jackson.Containers in project providence by morimekta.

the class JacksonTest method testJsonSerializerCompat.

@Test
public void testJsonSerializerCompat() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ProvidenceModule.register(mapper);
    JsonSerializer compact = new JsonSerializer();
    JsonSerializer pretty = new JsonSerializer().pretty();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (int i = 0; i < 100; ++i) {
        Containers containers = generator.generate(Containers.kDescriptor);
        out.reset();
        compact.serialize(out, containers);
        Containers res = mapper.readValue(out.toByteArray(), Containers.class);
        assertThat(res, is(equalToMessage(containers)));
        out.reset();
        pretty.serialize(out, containers);
        res = mapper.readValue(out.toByteArray(), Containers.class);
        assertThat(res, is(equalToMessage(containers)));
    }
}
Also used : Containers(net.morimekta.test.jackson.Containers) JsonSerializer(net.morimekta.providence.serializer.JsonSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 JsonSerializer (net.morimekta.providence.serializer.JsonSerializer)1 Containers (net.morimekta.test.jackson.Containers)1 Test (org.junit.Test)1