Search in sources :

Example 1 with FormatterUUT

use of com.instagram.common.json.annotation.processor.uut.FormatterUUT 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());
}
Also used : JSONWriter(org.json.JSONWriter) ExtensibleJSONWriter(com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter) StringWriter(java.io.StringWriter) FormatterUUT(com.instagram.common.json.annotation.processor.uut.FormatterUUT) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Example 2 with FormatterUUT

use of com.instagram.common.json.annotation.processor.uut.FormatterUUT 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());
}
Also used : JSONWriter(org.json.JSONWriter) ExtensibleJSONWriter(com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter) StringWriter(java.io.StringWriter) FormatterUUT(com.instagram.common.json.annotation.processor.uut.FormatterUUT) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)2 FormatterUUT (com.instagram.common.json.annotation.processor.uut.FormatterUUT)2 StringWriter (java.io.StringWriter)2 JSONWriter (org.json.JSONWriter)2 Test (org.junit.Test)2