Search in sources :

Example 1 with InterfaceImplementationUUT

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

the class SerializeTest method serializeInterfaceNoFormattersTest.

@Test
public void serializeInterfaceNoFormattersTest() throws IOException {
    StringWriter stringWriter = new StringWriter();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
    ;
    InterfaceImplementationUUT obj = new InterfaceImplementationUUT();
    obj.mStringField = "testValue";
    WrapperInterfaceUUT wrapper = new WrapperInterfaceUUT();
    wrapper.mInterfaceParentNoFormatters = obj;
    WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
    jsonGenerator.close();
    String serialized = stringWriter.toString();
    WrapperInterfaceUUT parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
    assertNotNull(parsed);
    assertTrue(parsed.mInterfaceParentNoFormatters instanceof InterfaceImplementationUUT);
    InterfaceImplementationUUT parsedObj = (InterfaceImplementationUUT) parsed.mInterfaceParentNoFormatters;
    assertEquals(obj.mStringField, parsedObj.mStringField);
}
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) Test(org.junit.Test)

Example 2 with InterfaceImplementationUUT

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

the class SerializeTest method serializeInterfaceDynamicTest.

@Test
public void serializeInterfaceDynamicTest() throws IOException {
    StringWriter stringWriter = new StringWriter();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
    ;
    InterfaceImplementationUUT obj = new InterfaceImplementationUUT();
    obj.mStringField = "testValue";
    InterfaceParentDynamicUUTHelper.DISPATCHER.register(InterfaceImplementationUUT.TYPE_NAME, InterfaceImplementationUUT.ADAPTER);
    WrapperInterfaceUUT wrapper = new WrapperInterfaceUUT();
    wrapper.mInterfaceParentDynamic = obj;
    WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
    jsonGenerator.close();
    String serialized = stringWriter.toString();
    WrapperInterfaceUUT parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
    assertNotNull(parsed);
    assertTrue(parsed.mInterfaceParentDynamic instanceof InterfaceImplementationUUT);
    InterfaceImplementationUUT parsedObj = (InterfaceImplementationUUT) parsed.mInterfaceParentDynamic;
    assertEquals(obj.mStringField, parsedObj.mStringField);
}
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) Test(org.junit.Test)

Example 3 with InterfaceImplementationUUT

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

the class SerializeTest method serializeInterfaceTest.

@Test
public void serializeInterfaceTest() throws IOException {
    StringWriter stringWriter = new StringWriter();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
    ;
    InterfaceImplementationUUT obj = new InterfaceImplementationUUT();
    obj.mStringField = "testValue";
    WrapperInterfaceUUT wrapper = new WrapperInterfaceUUT();
    wrapper.mInterfaceParent = obj;
    WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
    jsonGenerator.close();
    String serialized = stringWriter.toString();
    WrapperInterfaceUUT parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
    assertNotNull(parsed);
    assertTrue(parsed.mInterfaceParent instanceof InterfaceImplementationUUT);
    InterfaceImplementationUUT parsedObj = (InterfaceImplementationUUT) parsed.mInterfaceParent;
    assertEquals(obj.mStringField, parsedObj.mStringField);
}
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) Test(org.junit.Test)

Example 4 with InterfaceImplementationUUT

use of com.instagram.common.json.annotation.processor.parent.InterfaceImplementationUUT 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)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 InterfaceImplementationUUT (com.instagram.common.json.annotation.processor.parent.InterfaceImplementationUUT)4 StringWriter (java.io.StringWriter)4 Test (org.junit.Test)4 InterfaceImplementation2UUT (com.instagram.common.json.annotation.processor.parent.InterfaceImplementation2UUT)1