Skip to content

Commit 288a4e6

Browse files
committed
jodd
1 parent e2fd0e1 commit 288a4e6

File tree

10 files changed

+62
-3
lines changed

10 files changed

+62
-3
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ dependencies {
5858
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
5959
// nanojson
6060
compile group: 'com.grack', name: 'nanojson', version: '1.2'
61+
// jodd
62+
compile group: 'org.jodd', name: 'jodd-json', version: '3.8.0'
6163

6264
// Test
6365
testCompile group: 'junit', name: 'junit', version: '4.12'
6466

65-
// IMPORANT: Leave JMH at the end!
67+
// IMPORTANT: Leave JMH at the end!
6668
// JMH
6769
compile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.15'
6870
apt group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.15'

src/main/java/com/github/fabienrenaud/jjb/JsonBench.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ public Object nanojson() throws Exception {
7474
return null;
7575
}
7676

77+
public Object jodd() throws Exception {
78+
return null;
79+
}
80+
7781
}

src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,10 @@ public Object dsljson() throws Exception {
8080
public Object logansquare() throws Exception {
8181
return LoganSquare.parse(JSON_SOURCE.nextInputStream(), JSON_SOURCE.pojoType());
8282
}
83+
84+
@Benchmark
85+
@Override
86+
public Object jodd() throws Exception {
87+
return JSON_SOURCE.provider().joddDeser().parse(JSON_SOURCE.nextString(), JSON_SOURCE.pojoType());
88+
}
8389
}

src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ public Object logansquare() throws Exception {
100100
LoganSquare.serialize(JSON_SOURCE.nextPojo(), baos);
101101
return baos;
102102
}
103+
104+
@Benchmark
105+
@Override
106+
public Object jodd() throws Exception {
107+
return JSON_SOURCE.provider().joddSer().serialize(JSON_SOURCE.nextPojo());
108+
}
103109
}

src/main/java/com/github/fabienrenaud/jjb/model/Users.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
*/
1313
@JsonObject
1414
@CompiledJson
15+
@jodd.json.meta.JSON
1516
public class Users {
1617

1718
@JsonField
19+
@jodd.json.meta.JSON
1820
public List<User> users;
1921

2022
@Override
@@ -79,9 +81,11 @@ public static final class User {
7981
public double longitude;
8082
@JsonField
8183
@JsonAttribute(nullable = false)
84+
@jodd.json.meta.JSON
8285
public List<String> tags;
8386
@JsonField
8487
@JsonAttribute(nullable = false)
88+
@jodd.json.meta.JSON
8589
public List<Friend> friends;
8690
@JsonField
8791
public String greeting;

src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public interface JsonProvider<T> {
3737
Map<String, Object> jsonioStreamOptions();
3838

3939
DslJson<T> dsljson();
40+
41+
jodd.json.JsonParser joddDeser();
42+
43+
jodd.json.JsonSerializer joddSer();
4044
}

src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,28 @@ public Map<String, Object> jsonioStreamOptions() {
102102
public DslJson<Users> dsljson() {
103103
return dsljson;
104104
}
105+
106+
@Override
107+
public jodd.json.JsonParser joddDeser() {
108+
return JODD_DESER.get();
109+
}
110+
111+
@Override
112+
public jodd.json.JsonSerializer joddSer() {
113+
return JODD_SER.get();
114+
}
115+
116+
private static final ThreadLocal<jodd.json.JsonParser> JODD_DESER = new ThreadLocal<jodd.json.JsonParser>() {
117+
@Override
118+
protected jodd.json.JsonParser initialValue() {
119+
return new jodd.json.JsonParser();
120+
}
121+
};
122+
123+
private static final ThreadLocal<jodd.json.JsonSerializer> JODD_SER = new ThreadLocal<jodd.json.JsonSerializer>() {
124+
@Override
125+
protected jodd.json.JsonSerializer initialValue() {
126+
return new jodd.json.JsonSerializer();
127+
}
128+
};
105129
}

src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public enum BenchSupport {
2525
new Libapi(Library.DSLJSON, Api.DATABIND),
2626
new Libapi(Library.LOGANSQUARE, Api.DATABIND),
2727
new Libapi(Library.JSONSIMPLE, Api.STREAM),
28-
new Libapi(Library.NANOJSON, Api.STREAM)
28+
new Libapi(Library.NANOJSON, Api.STREAM),
29+
new Libapi(Library.JODD, Api.DATABIND)
2930
);
3031

3132
private final List<Libapi> libapis;

src/main/java/com/github/fabienrenaud/jjb/support/Library.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public enum Library {
2222
DSLJSON,
2323
LOGANSQUARE,
2424
JSONSIMPLE,
25-
NANOJSON;
25+
NANOJSON,
26+
JODD;
2627

2728
public static Set<Library> fromCsv(String str) {
2829
if (str == null || str.trim().isEmpty()) {

src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,11 @@ public void nanojson() throws Exception {
169169
test(Library.NANOJSON, BENCH.nanojson());
170170
}
171171
}
172+
173+
@Test
174+
public void jodd() throws Exception {
175+
for (int i = 0; i < ITERATIONS; i++) {
176+
test(Library.JODD, BENCH.jodd());
177+
}
178+
}
172179
}

0 commit comments

Comments
 (0)