Search in sources :

Example 71 with JsonFactory

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

the class TestDeserializePerf 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 TestDeserializePerf().testWith(mapperSlow, mapperFast);
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 72 with JsonFactory

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

the class TestJvmDeserPerf method test.

public void test() throws Exception {
    int sum = 0;
    final MediaItem item = buildItem();
    JsonFactory jsonF = //            new org.codehaus.jackson.smile.SmileFactory();
    new JsonFactory();
    final ObjectMapper jsonMapper = new ObjectMapper(jsonF);
    jsonMapper.registerModule(new com.fasterxml.jackson.module.afterburner.AfterburnerModule());
    byte[] json = jsonMapper.writeValueAsBytes(item);
    System.out.println("Warmed up: data size is " + json.length + " bytes; " + REPS + " reps -> " + ((REPS * json.length) >> 10) + " kB per iteration");
    System.out.println();
    int round = 0;
    while (true) {
        //            try {  Thread.sleep(100L); } catch (InterruptedException ie) { }
        round = (round + 1) % 2;
        long curr = System.currentTimeMillis();
        String msg;
        boolean lf = (round == 0);
        switch(round) {
            case 0:
                msg = "Deserialize/databind, JSON";
                sum += testDeser(jsonMapper, json, REPS);
                break;
            case 1:
                msg = "Deserialize/manual, JSON";
                sum += testDeser(jsonMapper.getFactory(), json, REPS);
                break;
            default:
                throw new Error("Internal error");
        }
        curr = System.currentTimeMillis() - curr;
        if (lf) {
            System.out.println();
        }
        System.out.println("Test '" + msg + "' -> " + curr + " msecs (" + (sum & 0xFF) + ").");
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 73 with JsonFactory

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

the class TestParserOverrides method testTokenAccess.

/*
    /**********************************************************
    /* Wrappers, to test stream and reader-based parsers
    /**********************************************************
     */
public void testTokenAccess() throws Exception {
    JsonFactory jf = new JsonFactory();
    _testTokenAccess(jf, false);
    _testTokenAccess(jf, true);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory)

Example 74 with JsonFactory

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

the class TestJDKSerializability method testJsonFactorySerializable.

public void testJsonFactorySerializable() throws Exception {
    JsonFactory f = new JsonFactory();
    String origJson = "{\"simple\":[1,true,{}]}";
    assertEquals(origJson, _copyJson(f, origJson, false));
    // Ok: freeze dry factory, thaw, and try to use again:
    byte[] frozen = jdkSerialize(f);
    JsonFactory f2 = jdkDeserialize(frozen);
    assertNotNull(f2);
    assertEquals(origJson, _copyJson(f2, origJson, false));
    // Let's also try byte-based variant, for fun...
    assertEquals(origJson, _copyJson(f2, origJson, true));
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory)

Example 75 with JsonFactory

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

the class TestJDKSerializability method testLocation.

public void testLocation() throws Exception {
    JsonFactory jf = new JsonFactory();
    JsonParser jp = jf.createParser("  { }");
    assertToken(JsonToken.START_OBJECT, jp.nextToken());
    JsonLocation loc = jp.getCurrentLocation();
    byte[] stuff = jdkSerialize(loc);
    JsonLocation loc2 = jdkDeserialize(stuff);
    assertNotNull(loc2);
    assertEquals(loc.getLineNr(), loc2.getLineNr());
    assertEquals(loc.getColumnNr(), loc2.getColumnNr());
    jp.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)115 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)45 Test (org.junit.Test)37 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)35 StringWriter (java.io.StringWriter)34 JsonParser (com.fasterxml.jackson.core.JsonParser)26 IOException (java.io.IOException)16 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)15 Map (java.util.Map)14 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)9 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8 List (java.util.List)8 Reader (java.io.Reader)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)5 FileInputStream (java.io.FileInputStream)4 JSONWriter (org.json.JSONWriter)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BaseJsonHttpResponseHandler (com.loopj.android.http.BaseJsonHttpResponseHandler)3