diff --git a/build.gradle b/build.gradle index 8cb13f4..122662c 100644 --- a/build.gradle +++ b/build.gradle @@ -58,11 +58,13 @@ dependencies { compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' // nanojson compile group: 'com.grack', name: 'nanojson', version: '1.2' + // jodd + compile group: 'org.jodd', name: 'jodd-json', version: '3.8.0' // Test testCompile group: 'junit', name: 'junit', version: '4.12' - // IMPORANT: Leave JMH at the end! + // IMPORTANT: Leave JMH at the end! // JMH compile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.15' apt group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.15' diff --git a/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java b/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java index 7e03931..7231489 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java +++ b/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java @@ -74,4 +74,8 @@ public Object nanojson() throws Exception { return null; } + public Object jodd() throws Exception { + return null; + } + } diff --git a/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java b/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java index eb1f749..7376ef2 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java +++ b/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java @@ -80,4 +80,10 @@ public Object dsljson() throws Exception { public Object logansquare() throws Exception { return LoganSquare.parse(JSON_SOURCE.nextInputStream(), JSON_SOURCE.pojoType()); } + + @Benchmark + @Override + public Object jodd() throws Exception { + return JSON_SOURCE.provider().joddDeser().parse(JSON_SOURCE.nextString(), JSON_SOURCE.pojoType()); + } } diff --git a/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java b/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java index da4da5f..ebcf46b 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java +++ b/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java @@ -100,4 +100,10 @@ public Object logansquare() throws Exception { LoganSquare.serialize(JSON_SOURCE.nextPojo(), baos); return baos; } + + @Benchmark + @Override + public Object jodd() throws Exception { + return JSON_SOURCE.provider().joddSer().serialize(JSON_SOURCE.nextPojo()); + } } diff --git a/src/main/java/com/github/fabienrenaud/jjb/model/Users.java b/src/main/java/com/github/fabienrenaud/jjb/model/Users.java index fead3ef..7811f9c 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/model/Users.java +++ b/src/main/java/com/github/fabienrenaud/jjb/model/Users.java @@ -12,9 +12,11 @@ */ @JsonObject @CompiledJson +@jodd.json.meta.JSON public class Users { @JsonField + @jodd.json.meta.JSON public List users; @Override @@ -79,9 +81,11 @@ public static final class User { public double longitude; @JsonField @JsonAttribute(nullable = false) + @jodd.json.meta.JSON public List tags; @JsonField @JsonAttribute(nullable = false) + @jodd.json.meta.JSON public List friends; @JsonField public String greeting; diff --git a/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java b/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java index 4d64ff9..d70ef15 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java +++ b/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java @@ -37,4 +37,8 @@ public interface JsonProvider { Map jsonioStreamOptions(); DslJson dsljson(); + + jodd.json.JsonParser joddDeser(); + + jodd.json.JsonSerializer joddSer(); } diff --git a/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java b/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java index 3ee59ca..9c92d67 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java +++ b/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java @@ -102,4 +102,28 @@ public Map jsonioStreamOptions() { public DslJson dsljson() { return dsljson; } + + @Override + public jodd.json.JsonParser joddDeser() { + return JODD_DESER.get(); + } + + @Override + public jodd.json.JsonSerializer joddSer() { + return JODD_SER.get(); + } + + private static final ThreadLocal JODD_DESER = new ThreadLocal() { + @Override + protected jodd.json.JsonParser initialValue() { + return new jodd.json.JsonParser(); + } + }; + + private static final ThreadLocal JODD_SER = new ThreadLocal() { + @Override + protected jodd.json.JsonSerializer initialValue() { + return new jodd.json.JsonSerializer(); + } + }; } diff --git a/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java b/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java index 0931628..8145956 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java +++ b/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java @@ -25,7 +25,8 @@ public enum BenchSupport { new Libapi(Library.DSLJSON, Api.DATABIND), new Libapi(Library.LOGANSQUARE, Api.DATABIND), new Libapi(Library.JSONSIMPLE, Api.STREAM), - new Libapi(Library.NANOJSON, Api.STREAM) + new Libapi(Library.NANOJSON, Api.STREAM), + new Libapi(Library.JODD, Api.DATABIND) ); private final List libapis; diff --git a/src/main/java/com/github/fabienrenaud/jjb/support/Library.java b/src/main/java/com/github/fabienrenaud/jjb/support/Library.java index 63fcb16..e95e597 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/support/Library.java +++ b/src/main/java/com/github/fabienrenaud/jjb/support/Library.java @@ -22,7 +22,8 @@ public enum Library { DSLJSON, LOGANSQUARE, JSONSIMPLE, - NANOJSON; + NANOJSON, + JODD; public static Set fromCsv(String str) { if (str == null || str.trim().isEmpty()) { diff --git a/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java b/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java index 236705a..390a520 100644 --- a/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java +++ b/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java @@ -169,4 +169,11 @@ public void nanojson() throws Exception { test(Library.NANOJSON, BENCH.nanojson()); } } + + @Test + public void jodd() throws Exception { + for (int i = 0; i < ITERATIONS; i++) { + test(Library.JODD, BENCH.jodd()); + } + } }