+54
-7
lines changedFilter options
+54
-7
lines changed Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ dependencies {
60
60
compile group: 'com.grack', name: 'nanojson', version: '1.2'
61
61
// jodd
62
62
compile group: 'org.jodd', name: 'jodd-json', version: '3.8.0'
63
+
// moshi
64
+
compile group: 'com.squareup.moshi', name: 'moshi', version: '1.3.1'
63
65
64
66
// Test
65
67
testCompile group: 'junit', name: 'junit', version: '4.12'
Original file line number Diff line number Diff line change
@@ -78,4 +78,8 @@ public Object jodd() throws Exception {
78
78
return null;
79
79
}
80
80
81
+
public Object moshi() throws Exception {
82
+
return null;
83
+
}
84
+
81
85
}
Original file line number Diff line number Diff line change
@@ -56,5 +56,4 @@ protected com.dslplatform.json.JsonWriter initialValue() {
56
56
}
57
57
};
58
58
59
-
60
59
}
Original file line number Diff line number Diff line change
@@ -4,11 +4,9 @@
4
4
import com.github.fabienrenaud.jjb.provider.JsonProvider;
5
5
import com.github.fabienrenaud.jjb.stream.StreamDeserializer;
6
6
import com.github.fabienrenaud.jjb.stream.StreamSerializer;
7
+
import okio.*;
7
8
8
-
import java.io.ByteArrayInputStream;
9
-
import java.io.InputStream;
10
-
import java.io.InputStreamReader;
11
-
import java.io.Reader;
9
+
import java.io.*;
12
10
import java.util.Random;
13
11
14
12
/**
@@ -94,6 +92,14 @@ public Reader nextReader() {
94
92
return new InputStreamReader(nextInputStream());
95
93
}
96
94
95
+
public BufferedSource nextOkioBufferedSource() {
96
+
return Okio.buffer(new ForwardingSource(Okio.source(nextInputStream())) {
97
+
@Override
98
+
public void close() throws IOException {
99
+
}
100
+
});
101
+
}
102
+
97
103
public T nextPojo() {
98
104
return jsonAsObject[index(jsonAsObject.length)];
99
105
}
Original file line number Diff line number Diff line change
@@ -86,4 +86,10 @@ public Object logansquare() throws Exception {
86
86
public Object jodd() throws Exception {
87
87
return JSON_SOURCE.provider().joddDeser().parse(JSON_SOURCE.nextString(), JSON_SOURCE.pojoType());
88
88
}
89
+
90
+
@Benchmark
91
+
@Override
92
+
public Object moshi() throws Exception {
93
+
return JSON_SOURCE.provider().moshi().fromJson(JSON_SOURCE.nextOkioBufferedSource());
94
+
}
89
95
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
5
5
import com.bluelinelabs.logansquare.LoganSquare;
6
6
import com.github.fabienrenaud.jjb.JsonBench;
7
7
import com.github.fabienrenaud.jjb.JsonUtils;
8
+
import okio.BufferedSink;
9
+
import okio.Okio;
8
10
import org.openjdk.jmh.annotations.Benchmark;
9
11
10
12
import java.io.ByteArrayOutputStream;
@@ -106,4 +108,14 @@ public Object logansquare() throws Exception {
106
108
public Object jodd() throws Exception {
107
109
return JSON_SOURCE.provider().joddSer().serialize(JSON_SOURCE.nextPojo());
108
110
}
111
+
112
+
@Benchmark
113
+
@Override
114
+
public Object moshi() throws Exception {
115
+
ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream();
116
+
BufferedSink sink = Okio.buffer(Okio.sink(baos));
117
+
JSON_SOURCE.provider().moshi().toJson(sink, JSON_SOURCE.nextPojo());
118
+
sink.flush();
119
+
return baos;
120
+
}
109
121
}
Original file line number Diff line number Diff line change
@@ -41,4 +41,6 @@ public interface JsonProvider<T> {
41
41
jodd.json.JsonParser joddDeser();
42
42
43
43
jodd.json.JsonSerializer joddSer();
44
+
45
+
com.squareup.moshi.JsonAdapter<T> moshi();
44
46
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
9
9
import com.github.fabienrenaud.jjb.model.Users;
10
10
import com.google.gson.Gson;
11
11
import com.owlike.genson.Genson;
12
+
import com.squareup.moshi.Moshi;
12
13
import flexjson.JSONDeserializer;
13
14
import flexjson.JSONSerializer;
14
15
import org.apache.johnzon.mapper.Mapper;
@@ -29,6 +30,7 @@ public class UsersJsonProvider implements JsonProvider<Users> {
29
30
private final JSONDeserializer<Users> flexjsonDeser = new JSONDeserializer<>();
30
31
private final org.boon.json.ObjectMapper boon = org.boon.json.JsonFactory.create();
31
32
private final org.apache.johnzon.mapper.Mapper johnson;
33
+
private final com.squareup.moshi.JsonAdapter<Users> moshi = new Moshi.Builder().build().adapter(Users.class);
32
34
33
35
/*
34
36
* DSL-json
@@ -112,6 +114,11 @@ public jodd.json.JsonSerializer joddSer() {
112
114
return JODD_SER.get();
113
115
}
114
116
117
+
@Override
118
+
public com.squareup.moshi.JsonAdapter<Users> moshi() {
119
+
return moshi;
120
+
}
121
+
115
122
private static final ThreadLocal<flexjson.JSONSerializer> FLEXJSON_SER = new ThreadLocal<flexjson.JSONSerializer>() {
116
123
@Override
117
124
protected JSONSerializer initialValue() {
Original file line number Diff line number Diff line change
@@ -26,7 +26,8 @@ public enum BenchSupport {
26
26
new Libapi(Library.LOGANSQUARE, Api.DATABIND),
27
27
new Libapi(Library.JSONSIMPLE, Api.STREAM),
28
28
new Libapi(Library.NANOJSON, Api.STREAM),
29
-
new Libapi(Library.JODD, Api.DATABIND)
29
+
new Libapi(Library.JODD, Api.DATABIND),
30
+
new Libapi(Library.MOSHI, Api.DATABIND)
30
31
);
31
32
32
33
private final List<Libapi> libapis;
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ public enum Library {
23
23
LOGANSQUARE,
24
24
JSONSIMPLE,
25
25
NANOJSON,
26
-
JODD;
26
+
JODD,
27
+
MOSHI;
27
28
28
29
public static Set<Library> fromCsv(String str) {
29
30
if (str == null || str.trim().isEmpty()) {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4