Search in sources :

Example 31 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory 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 : ExtensibleJSONWriter(com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter) JSONWriter(org.json.JSONWriter) 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 32 with JsonFactory

use of 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());
}
Also used : ExtensibleJSONWriter(com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter) JSONWriter(org.json.JSONWriter) 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 33 with JsonFactory

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

Example 34 with JsonFactory

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

Example 35 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project jackson-module-afterburner by FasterXML.

the class TestSerializePerf method main.

public static void main(String[] args) throws Exception {
    //        JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
    JsonFactory f = new JsonFactory();
    ObjectMapper mapperSlow = new ObjectMapper(f);
    ObjectMapper mapperFast = new ObjectMapper(f);
    // !!! TEST -- to get profile info, comment out:
    mapperSlow.registerModule(new AfterburnerModule());
    mapperFast.registerModule(new AfterburnerModule());
    new TestSerializePerf().testWith(mapperSlow, mapperFast);
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 Test (org.junit.Test)31 StringWriter (java.io.StringWriter)29 JsonParser (com.fasterxml.jackson.core.JsonParser)24 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)15 IOException (java.io.IOException)14 Map (java.util.Map)14 HashMap (java.util.HashMap)11 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 FileInputStream (java.io.FileInputStream)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 Reader (java.io.Reader)5 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)5 File (java.io.File)4 JSONWriter (org.json.JSONWriter)4 BaseJsonHttpResponseHandler (com.loopj.android.http.BaseJsonHttpResponseHandler)3