Search in sources :

Example 1 with InterfaceImplementation2UUT

use of com.instagram.common.json.annotation.processor.parent.InterfaceImplementation2UUT in project ig-json-parser by Instagram.

the class SerializeTest method serializeInterfaceWithWrapperTest.

@Test
public void serializeInterfaceWithWrapperTest() throws IOException {
    StringWriter stringWriter;
    JsonGenerator jsonGenerator;
    InterfaceImplementationUUT obj = new InterfaceImplementationUUT();
    obj.mStringField = "testValue";
    InterfaceImplementation2UUT obj2 = new InterfaceImplementation2UUT();
    obj2.mIntegerField = 5;
    WrapperInterfaceUUT wrapper = new WrapperInterfaceUUT();
    stringWriter = new StringWriter();
    jsonGenerator = new JsonFactory().createGenerator(stringWriter);
    wrapper.mInterfaceParentWithWrapper = obj;
    WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
    jsonGenerator.close();
    String serialized = stringWriter.toString();
    WrapperInterfaceUUT parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
    assertNotNull(parsed);
    assertTrue(parsed.mInterfaceParentWithWrapper instanceof InterfaceImplementationUUT);
    InterfaceImplementationUUT parsedObj = (InterfaceImplementationUUT) parsed.mInterfaceParentWithWrapper;
    assertEquals(obj.mStringField, parsedObj.mStringField);
    stringWriter = new StringWriter();
    jsonGenerator = new JsonFactory().createGenerator(stringWriter);
    wrapper.mInterfaceParentWithWrapper = obj2;
    WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
    jsonGenerator.close();
    serialized = stringWriter.toString();
    parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
    assertNotNull(parsed);
    assertTrue(parsed.mInterfaceParentWithWrapper instanceof InterfaceImplementation2UUT);
    InterfaceImplementation2UUT parsedObj2 = (InterfaceImplementation2UUT) parsed.mInterfaceParentWithWrapper;
    assertEquals(obj2.mIntegerField, parsedObj2.mIntegerField);
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) InterfaceImplementationUUT(com.instagram.common.json.annotation.processor.parent.InterfaceImplementationUUT) InterfaceImplementation2UUT(com.instagram.common.json.annotation.processor.parent.InterfaceImplementation2UUT) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 InterfaceImplementation2UUT (com.instagram.common.json.annotation.processor.parent.InterfaceImplementation2UUT)1 InterfaceImplementationUUT (com.instagram.common.json.annotation.processor.parent.InterfaceImplementationUUT)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1