File tree Expand file tree Collapse file tree 4 files changed +114
-0
lines changed
src/main/java/com/cowtowncoder/jsonperf/dzone Expand file tree Collapse file tree 4 files changed +114
-0
lines changed Original file line number Diff line number Diff line change 8989 <version >2.5</version >
9090 </dependency >
9191
92+ <!-- and Alibaba Fastjson -->
93+
94+ <dependency >
95+ <groupId >com.alibaba</groupId >
96+ <artifactId >fastjson</artifactId >
97+ <version >1.2.11</version >
98+ </dependency >
99+
92100 <!-- Moshi, by some of same folks as GSON -->
93101 <dependency >
94102 <groupId >com.squareup.moshi</groupId >
Original file line number Diff line number Diff line change 1+ package com .cowtowncoder .jsonperf .dzone .read ;
2+
3+ import java .util .Map ;
4+ import java .util .concurrent .TimeUnit ;
5+
6+ import org .openjdk .jmh .annotations .OutputTimeUnit ;
7+ import org .openjdk .jmh .annotations .Scope ;
8+ import org .openjdk .jmh .annotations .State ;
9+
10+ import com .alibaba .fastjson .JSON ;
11+ import com .alibaba .fastjson .parser .Feature ;
12+
13+ @ State (Scope .Thread )
14+ @ OutputTimeUnit (TimeUnit .SECONDS )
15+ public class DZoneReadMapFastjson extends DZoneReadTestBase <Map <Object ,Object >>
16+ {
17+
18+ public DZoneReadMapFastjson ()
19+ {
20+ }
21+
22+ @ SuppressWarnings ("unchecked" )
23+ @ Override
24+ public Map <Object ,Object > _readItems (byte [] input ) throws Exception {
25+ return (Map <Object ,Object >) JSON .parse (input , Feature .DisableCircularReferenceDetect );
26+ }
27+
28+ @ SuppressWarnings ("unchecked" )
29+ @ Override
30+ public Map <Object ,Object > _readItems (String input ) throws Exception {
31+ return (Map <Object ,Object >) JSON .parse (input , Feature .DisableCircularReferenceDetect );
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ package com .cowtowncoder .jsonperf .dzone .read ;
2+
3+ import java .util .concurrent .TimeUnit ;
4+
5+ import org .openjdk .jmh .annotations .OutputTimeUnit ;
6+ import org .openjdk .jmh .annotations .Scope ;
7+ import org .openjdk .jmh .annotations .State ;
8+
9+ import com .alibaba .fastjson .JSON ;
10+ import com .alibaba .fastjson .parser .Feature ;
11+ import com .cowtowncoder .jsonperf .dzone .MeasurementPOJO ;
12+
13+ @ State (Scope .Thread )
14+ @ OutputTimeUnit (TimeUnit .SECONDS )
15+ public class DZoneReadPojoFastjson extends DZoneReadTestBase <MeasurementPOJO >
16+ {
17+
18+ public DZoneReadPojoFastjson ()
19+ {
20+ }
21+
22+ @ Override
23+ public MeasurementPOJO _readItems (byte [] input ) throws Exception {
24+ return JSON .parseObject (input , MeasurementPOJO .class , Feature .DisableCircularReferenceDetect );
25+ }
26+
27+ @ Override
28+ public MeasurementPOJO _readItems (String input ) throws Exception {
29+ return JSON .parseObject (input , MeasurementPOJO .class , Feature .DisableCircularReferenceDetect );
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package com .cowtowncoder .jsonperf .dzone .write ;
2+
3+ import java .io .OutputStream ;
4+ import java .io .Writer ;
5+ import java .util .concurrent .TimeUnit ;
6+
7+ import org .openjdk .jmh .annotations .OutputTimeUnit ;
8+ import org .openjdk .jmh .annotations .Scope ;
9+ import org .openjdk .jmh .annotations .State ;
10+
11+ import com .alibaba .fastjson .JSON ;
12+ import com .alibaba .fastjson .serializer .SerializerFeature ;
13+ import com .cowtowncoder .jsonperf .dzone .MeasurementPOJO ;
14+
15+ @ State (Scope .Thread )
16+ @ OutputTimeUnit (TimeUnit .SECONDS )
17+ public class DZoneWriteFastjson extends DZoneWriteTestBase
18+ {
19+
20+ public DZoneWriteFastjson ()
21+ {
22+ }
23+
24+ @ Override
25+ public int _writeItems (MeasurementPOJO items , OutputStream out ) throws Exception
26+ {
27+ JSON .writeJSONString (out , items , SerializerFeature .DisableCircularReferenceDetect );
28+ return items .size ();
29+ }
30+
31+ @ Override
32+ public int _writeItems (MeasurementPOJO items , Writer out ) throws Exception
33+ {
34+ JSON .writeJSONString (out , items , SerializerFeature .DisableCircularReferenceDetect );
35+ return items .size ();
36+ }
37+
38+ @ Override
39+ public String _writeAsString (MeasurementPOJO items ) throws Exception {
40+ return JSON .toJSONString (items , SerializerFeature .DisableCircularReferenceDetect );
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments