use of com.fasterxml.jackson.core.JsonParser in project ig-json-parser by Instagram.
the class DeserializeTest method valueExtractTest.
@Test
public void valueExtractTest() throws IOException, JSONException {
final int encodedValue = 25;
final int deserializedValue = 40;
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key(FormatterUUT.VALUE_FORMATTER_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.getValueFormatter());
}
use of com.fasterxml.jackson.core.JsonParser 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());
}
use of com.fasterxml.jackson.core.JsonParser in project ig-json-parser by Instagram.
the class DeserializeTest method malformedArrayEntry.
@Test
public void malformedArrayEntry() throws IOException, JSONException {
final List<Integer> integerList = Lists.newArrayList(1, null, 3, 4);
final int subIntValue = 30;
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(StrictListParseUUT.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(StrictListParseUUT.SUBOBJECT_LIST_FIELD_NAME).object().key(StrictListParseUUT.SubobjectParseUUT.INT_FIELD_NAME).value(subIntValue).endObject().endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
StrictListParseUUT uut = StrictListParseUUT__JsonHelper.parseFromJson(jp);
assertEquals(3, uut.integerListField.size());
assertEquals(1, uut.integerListField.get(0).intValue());
assertEquals(3, uut.integerListField.get(1).intValue());
assertEquals(4, uut.integerListField.get(2).intValue());
}
use of com.fasterxml.jackson.core.JsonParser in project ig-json-parser by Instagram.
the class DeserializeTest method postprocessTest.
@Test
public void postprocessTest() throws IOException, JSONException {
final int value = 25;
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key(PostprocessingUUT.FIELD_NAME).value(value).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
PostprocessingUUT uut = PostprocessingUUT__JsonHelper.parseFromJson(jp);
assertSame(value + 1, uut.getValue());
}
use of com.fasterxml.jackson.core.JsonParser in project jackson-databind by FasterXML.
the class ExceptionSerializationTest method testSimpleOther.
// to double-check [databind#1413]
public void testSimpleOther() throws Exception {
JsonParser p = MAPPER.getFactory().createParser("{ }");
InvalidFormatException exc = InvalidFormatException.from(p, "Test", getClass(), String.class);
String json = MAPPER.writeValueAsString(exc);
p.close();
assertNotNull(json);
}
Aggregations