22
33import com .cedarsoftware .util .io .JsonReader ;
44import com .cedarsoftware .util .io .JsonWriter ;
5- import com .dslplatform .json .ConfigureJava8 ;
65import com .dslplatform .json .DslJson ;
76import com .dslplatform .json .runtime .Settings ;
87import com .fasterxml .jackson .core .JsonFactory ;
1110import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
1211import com .fasterxml .jackson .module .afterburner .AfterburnerModule ;
1312import com .github .fabienrenaud .jjb .model .Clients ;
14- import com .google .gson .*;
13+ import com .google .gson .Gson ;
14+ import com .google .gson .GsonBuilder ;
15+ import com .google .gson .JsonDeserializer ;
16+ import com .google .gson .JsonPrimitive ;
17+ import com .google .gson .JsonSerializer ;
1518import com .owlike .genson .Context ;
1619import com .owlike .genson .Converter ;
1720import com .owlike .genson .Genson ;
2225import flexjson .JSONDeserializer ;
2326import flexjson .JSONSerializer ;
2427import flexjson .transformer .AbstractTransformer ;
28+ import jodd .bean .JoddBean ;
2529import jodd .json .TypeJsonSerializer ;
2630import jodd .typeconverter .TypeConverter ;
2731import jodd .typeconverter .TypeConverterManager ;
3337import javax .json .bind .Jsonb ;
3438import java .io .IOException ;
3539import java .math .BigDecimal ;
36- import java .time .*;
40+ import java .time .LocalDate ;
41+ import java .time .OffsetDateTime ;
3742import java .util .Collections ;
3843import java .util .HashMap ;
3944import java .util .Map ;
@@ -55,26 +60,25 @@ public class ClientsJsonProvider implements JsonProvider<Clients> {
5560 .registerModule (new JavaTimeModule ())
5661 .configure (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS , false );
5762 private final JsonFactory jacksonFactory = new JsonFactory ();
58- private final Genson genson =
59- new GensonBuilder ()
60- .useDateAsTimestamp (false )
61- .withConverter (new Converter <LocalDate >() {
62- public void serialize (LocalDate object , com .owlike .genson .stream .ObjectWriter writer , Context ctx ) {
63- writer .writeString (object .toString ());
64- }
65- public LocalDate deserialize (ObjectReader reader , Context ctx ) {
66- return LocalDate .parse (reader .valueAsString ());
67- }
68- }, LocalDate .class )
69- .withConverter (new Converter <OffsetDateTime >() {
70- public void serialize (OffsetDateTime object , com .owlike .genson .stream .ObjectWriter writer , Context ctx ) {
71- writer .writeString (object .toString ());
72- }
73- public OffsetDateTime deserialize (ObjectReader reader , Context ctx ) {
74- return OffsetDateTime .parse (reader .valueAsString ());
75- }
76- }, OffsetDateTime .class )
77- .create ();
63+ private final Genson genson = new GensonBuilder ()
64+ .useDateAsTimestamp (false )
65+ .withConverter (new Converter <LocalDate >() {
66+ public void serialize (LocalDate object , com .owlike .genson .stream .ObjectWriter writer , Context ctx ) {
67+ writer .writeString (object .toString ());
68+ }
69+ public LocalDate deserialize (ObjectReader reader , Context ctx ) {
70+ return LocalDate .parse (reader .valueAsString ());
71+ }
72+ }, LocalDate .class )
73+ .withConverter (new Converter <OffsetDateTime >() {
74+ public void serialize (OffsetDateTime object , com .owlike .genson .stream .ObjectWriter writer , Context ctx ) {
75+ writer .writeString (object .toString ());
76+ }
77+ public OffsetDateTime deserialize (ObjectReader reader , Context ctx ) {
78+ return OffsetDateTime .parse (reader .valueAsString ());
79+ }
80+ }, OffsetDateTime .class )
81+ .create ();
7882 private final Jsonb yasson = new JsonBindingProvider ().create ()
7983 .withProvider (new org .glassfish .json .JsonProviderImpl ())
8084 .build ();
@@ -84,11 +88,10 @@ public void transform(Object o) {
8488 getContext ().writeQuoted (o .toString ());
8589 }
8690 };
87- private final JSONDeserializer <Clients > flexjsonDeser =
88- new JSONDeserializer <Clients >()
89- .use (UUID .class , (objectBinder , o , type , aClass ) -> UUID .fromString ((String ) o ))
90- .use (LocalDate .class , (objectBinder , o , type , aClass ) -> LocalDate .parse ((String ) o ))
91- .use (OffsetDateTime .class , (objectBinder , o , type , aClass ) -> OffsetDateTime .parse ((String ) o ));
91+ private final JSONDeserializer <Clients > flexjsonDeser = new JSONDeserializer <Clients >()
92+ .use (UUID .class , (objectBinder , o , type , aClass ) -> UUID .fromString ((String ) o ))
93+ .use (LocalDate .class , (objectBinder , o , type , aClass ) -> LocalDate .parse ((String ) o ))
94+ .use (OffsetDateTime .class , (objectBinder , o , type , aClass ) -> OffsetDateTime .parse ((String ) o ));
9295
9396 private final org .boon .json .ObjectMapper boon = org .boon .json .JsonFactory .create ();
9497 private final Mapper johnzon ;
@@ -156,9 +159,11 @@ public ClientsJsonProvider() {
156159 .setAccessModeName ("field" ) // default is "strict-method" which doesn't work nicely with public attributes
157160 .build ();
158161
159- TypeConverterManager .register (UUID .class , (TypeConverter <UUID >) value -> UUID .fromString ((String )value ));
160- TypeConverterManager .register (LocalDate .class , (TypeConverter <LocalDate >) value -> LocalDate .parse ((String )value ));
161- TypeConverterManager .register (OffsetDateTime .class , (TypeConverter <OffsetDateTime >) value -> OffsetDateTime .parse ((String )value ));
162+ TypeConverterManager joddTypeConverterManager = JoddBean .defaults ().getTypeConverterManager ();
163+ joddTypeConverterManager .register (UUID .class , (TypeConverter <UUID >) value -> UUID .fromString ((String )value ));
164+ joddTypeConverterManager .register (LocalDate .class , (TypeConverter <LocalDate >) value -> LocalDate .parse ((String )value ));
165+ joddTypeConverterManager .register (OffsetDateTime .class , (TypeConverter <OffsetDateTime >) value -> OffsetDateTime .parse ((String )value ));
166+
162167 }
163168
164169 @ Override
@@ -239,39 +244,24 @@ public com.squareup.moshi.JsonAdapter<Clients> moshi() {
239244 return moshi ;
240245 }
241246
242- private static final ThreadLocal <JSONSerializer > FLEXJSON_SER = new ThreadLocal <JSONSerializer >() {
243- @ Override
244- protected JSONSerializer initialValue () {
245- return new JSONSerializer ()
246- .transform (FLEX_IDENTITY , UUID .class )
247- .transform (FLEX_IDENTITY , LocalDate .class )
248- .transform (FLEX_IDENTITY , OffsetDateTime .class );
249- }
250- };
247+ private static final ThreadLocal <JSONSerializer > FLEXJSON_SER = ThreadLocal .withInitial (() -> new JSONSerializer ()
248+ .transform (FLEX_IDENTITY , UUID .class )
249+ .transform (FLEX_IDENTITY , LocalDate .class )
250+ .transform (FLEX_IDENTITY , OffsetDateTime .class ));
251251
252- private static final ThreadLocal <jodd .json .JsonParser > JODD_DESER = new ThreadLocal <jodd .json .JsonParser >() {
253- @ Override
254- protected jodd .json .JsonParser initialValue () {
255- return new jodd .json .JsonParser ();
256- }
257- };
252+ private static final ThreadLocal <jodd .json .JsonParser > JODD_DESER = ThreadLocal .withInitial (jodd .json .JsonParser ::new );
258253
259- private static final ThreadLocal <jodd .json .JsonSerializer > JODD_SER = new ThreadLocal <jodd .json .JsonSerializer >() {
260- @ Override
261- protected jodd .json .JsonSerializer initialValue () {
262- return new jodd .json .JsonSerializer ()
263- .withSerializer (UUID .class , (TypeJsonSerializer <UUID >) (jsonContext , value ) -> {
264- jsonContext .writeString (value .toString ());
265- return true ;
266- })
267- .withSerializer (LocalDate .class , (TypeJsonSerializer <LocalDate >) (jsonContext , value ) -> {
268- jsonContext .writeString (value .toString ());
269- return true ;
270- })
271- .withSerializer (OffsetDateTime .class , (TypeJsonSerializer <OffsetDateTime >) (jsonContext , value ) -> {
272- jsonContext .writeString (value .toString ());
273- return true ;
274- });
275- }
276- };
254+ private static final ThreadLocal <jodd .json .JsonSerializer > JODD_SER = ThreadLocal .withInitial (() -> new jodd .json .JsonSerializer ()
255+ .withSerializer (UUID .class , (TypeJsonSerializer <UUID >) (jsonContext , value ) -> {
256+ jsonContext .writeString (value .toString ());
257+ return true ;
258+ })
259+ .withSerializer (LocalDate .class , (TypeJsonSerializer <LocalDate >) (jsonContext , value ) -> {
260+ jsonContext .writeString (value .toString ());
261+ return true ;
262+ })
263+ .withSerializer (OffsetDateTime .class , (TypeJsonSerializer <OffsetDateTime >) (jsonContext , value ) -> {
264+ jsonContext .writeString (value .toString ());
265+ return true ;
266+ }));
277267}
0 commit comments