use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class SerializeTest method simpleSerializeTest.
@Test
public void simpleSerializeTest() throws IOException, JSONException {
final int intValue = 25;
final int integerValue = 37;
final String stringValue = "hello world\r\n\'\"";
final List<Integer> integerList = Lists.newArrayList(1, 2, 3, 4);
final Queue<Integer> integerQueue = Queues.newArrayDeque(Arrays.asList(1, 2, 3, 4));
final Set<Integer> integerSet = Sets.newHashSet(1, 2, 3, 4);
final int subIntValue = 30;
final SimpleParseUUT.SubenumUUT subEnum = SimpleParseUUT.SubenumUUT.A;
final List<SimpleParseUUT.SubenumUUT> subEnumList = Lists.newArrayList(SimpleParseUUT.SubenumUUT.A, SimpleParseUUT.SubenumUUT.B);
SimpleParseUUT source = new SimpleParseUUT();
source.intField = intValue;
source.integerField = integerValue;
source.stringField = stringValue;
source.integerListField = integerList;
source.integerQueueField = integerQueue;
source.integerSetField = integerSet;
source.subobjectField = new SimpleParseUUT.SubobjectParseUUT();
source.subobjectField.intField = subIntValue;
source.subenumField = subEnum;
source.subenumFieldList = subEnumList;
StringWriter stringWriter = new StringWriter();
JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
SimpleParseUUT__JsonHelper.serializeToJson(jsonGenerator, source, true);
jsonGenerator.close();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
SimpleParseUUT parsed = SimpleParseUUT__JsonHelper.parseFromJson(jp);
assertSame(source.intField, parsed.intField);
assertEquals(source.integerField, parsed.integerField);
assertEquals(source.stringField, parsed.stringField);
assertEquals(source.integerListField, parsed.integerListField);
// NOTE: this is because ArrayDeque hilariously does not implement .equals()/.hashcode().
assertEquals(Lists.newArrayList(source.integerQueueField), Lists.newArrayList(parsed.integerQueueField));
assertEquals(source.integerSetField, parsed.integerSetField);
assertSame(source.subobjectField.intField, parsed.subobjectField.intField);
assertSame(source.subenumField, parsed.subenumField);
assertEquals(source.subenumFieldList, parsed.subenumFieldList);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class DeserializeTest method fieldAssignmentTest.
@Test
public void fieldAssignmentTest() throws IOException, JSONException {
final int encodedValue = 25;
final int deserializedValue = -encodedValue;
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key(FormatterUUT.FIELD_ASSIGNMENT_FIELD_NAME).value(encodedValue).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
FormatterUUT uut = FormatterUUT__JsonHelper.parseFromJson(jp);
assertSame(deserializedValue, uut.getFieldAssignmentFormatter());
}
Aggregations