use of com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter in project ig-json-parser by Instagram.
the class MalformedJsonTest method arrayInsteadOfScalar.
@Test
public void arrayInsteadOfScalar() throws IOException, JSONException {
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(SimpleParseUUT.STRING_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.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.support.ExtensibleJSONWriter 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);
}
Aggregations