use of com.instagram.common.json.annotation.processor.uut.SimpleParseUUT in project ig-json-parser by Instagram.
the class MalformedJsonTest method dictInsteadOfScalar.
@Test
public void dictInsteadOfScalar() throws IOException, JSONException {
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(SimpleParseUUT.STRING_FIELD_NAME).object().key("garbage").value("123").endObject().key(SimpleParseUUT.INT_FIELD_NAME).value(intValue).key(SimpleParseUUT.INTEGER_FIELD_NAME).value(integerValue).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
SimpleParseUUT uut = SimpleParseUUT__JsonHelper.parseFromJson(jp);
assertSame(intValue, uut.intField);
assertSame(integerValue, uut.integerField.intValue());
assertNull(uut.stringField);
}
use of com.instagram.common.json.annotation.processor.uut.SimpleParseUUT in project ig-json-parser by Instagram.
the class MalformedJsonTest method scalarInsteadOfObject.
@Test
public void scalarInsteadOfObject() 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 int subIntValue = 30;
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(SimpleParseUUT.INT_FIELD_NAME).value(intValue).key(SimpleParseUUT.INTEGER_FIELD_NAME).value(integerValue).key(SimpleParseUUT.STRING_FIELD_NAME).value(stringValue).key(SimpleParseUUT.INTEGER_LIST_FIELD_NAME).array().extend(new ExtensibleJSONWriter.Extender() {
@Override
public void extend(ExtensibleJSONWriter writer) throws JSONException {
for (Integer integer : integerList) {
writer.value(integer);
}
}
}).endArray().key(SimpleParseUUT.SUBOBJECT_FIELD_NAME).value(subIntValue).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
SimpleParseUUT uut = SimpleParseUUT__JsonHelper.parseFromJson(jp);
assertSame(intValue, uut.intField);
assertSame(integerValue, uut.integerField.intValue());
assertEquals(stringValue, uut.stringField);
assertEquals(integerList, uut.integerListField);
assertNull(uut.subobjectField);
}
Aggregations