1
1
package tools .jackson .databind .ser ;
2
2
3
- import java .math .BigDecimal ;
4
- import java .math .BigInteger ;
5
3
import java .net .InetAddress ;
6
4
import java .net .InetSocketAddress ;
7
5
import java .nio .ByteBuffer ;
@@ -50,51 +48,6 @@ public abstract class BasicSerializerFactory
50
48
extends SerializerFactory
51
49
implements java .io .Serializable
52
50
{
53
- /*
54
- /**********************************************************************
55
- /* Configuration, lookup tables/maps
56
- /**********************************************************************
57
- */
58
-
59
- /**
60
- * Since these are all JDK classes, we shouldn't have to worry
61
- * about ClassLoader used to load them. Rather, we can just
62
- * use the class name, and keep things simple and efficient.
63
- */
64
- protected final static HashMap <String , ValueSerializer <?>> _concrete ;
65
-
66
- static {
67
- HashMap <String , ValueSerializer <?>> concrete
68
- = new HashMap <String , ValueSerializer <?>>();
69
-
70
-
71
- /* String and string-like types (note: date types explicitly
72
- * not included -- can use either textual or numeric serialization)
73
- */
74
- concrete .put (String .class .getName (), StringSerializer .instance );
75
- final ToStringSerializer sls = ToStringSerializer .instance ;
76
- concrete .put (StringBuffer .class .getName (), sls );
77
- concrete .put (StringBuilder .class .getName (), sls );
78
- concrete .put (Character .class .getName (), sls );
79
- concrete .put (Character .TYPE .getName (), sls );
80
-
81
- // Primitives/wrappers for primitives (primitives needed for Beans)
82
- NumberSerializers .addAll (concrete );
83
- concrete .put (Boolean .TYPE .getName (), new BooleanSerializer (true ));
84
- concrete .put (Boolean .class .getName (), new BooleanSerializer (false ));
85
-
86
- // Other numbers, more complicated
87
- concrete .put (BigInteger .class .getName (), new NumberSerializer (BigInteger .class ));
88
- concrete .put (BigDecimal .class .getName (), new NumberSerializer (BigDecimal .class ));
89
-
90
- // Other discrete non-container types:
91
- // First, Date/Time zoo:
92
- concrete .put (Calendar .class .getName (), JavaUtilCalendarSerializer .instance );
93
- concrete .put (java .util .Date .class .getName (), JavaUtilDateSerializer .instance );
94
-
95
- _concrete = concrete ;
96
- }
97
-
98
51
/*
99
52
/**********************************************************************
100
53
/* Configuration
@@ -277,27 +230,10 @@ public TypeSerializer findPropertyContentTypeSerializer(SerializationContext ctx
277
230
278
231
/*
279
232
/**********************************************************************
280
- /* Overridable secondary serializer accessor methods
233
+ /* Secondary serializer accessor methods
281
234
/**********************************************************************
282
235
*/
283
236
284
- /**
285
- * Method that will use fast lookup (and identity comparison) methods to
286
- * see if we know serializer to use for given type.
287
- */
288
- protected final ValueSerializer <?> findSerializerByLookup (JavaType type ,
289
- SerializationConfig config , BeanDescription .Supplier beanDescRef ,
290
- JsonFormat .Value format , boolean staticTyping )
291
- {
292
- final Class <?> raw = type .getRawClass ();
293
- ValueSerializer <?> ser = JDKMiscSerializers .find (raw );
294
- if (ser == null ) {
295
- final String clsName = raw .getName ();
296
- ser = _concrete .get (clsName );
297
- }
298
- return ser ;
299
- }
300
-
301
237
/**
302
238
* Method called to see if one of primary per-class annotations
303
239
* (or related, like implementing of {@link JacksonSerializable})
@@ -347,15 +283,28 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
347
283
JavaType type , BeanDescription .Supplier beanDescRef , JsonFormat .Value formatOverrides ,
348
284
boolean staticTyping )
349
285
{
286
+ // First: simple lookups for concrete types
287
+ final Class <?> raw = type .getRawClass ();
288
+ ValueSerializer <?> ser ;
289
+
290
+ if ((ser = JDKCoreSerializers .find (raw )) != null ) {
291
+ return ser ;
292
+ }
293
+ if ((ser = JDKStringLikeSerializer .find (raw )) != null ) {
294
+ return ser ;
295
+ }
296
+ if ((ser = JDKMiscSerializers .find (raw )) != null ) {
297
+ return ser ;
298
+ }
299
+
350
300
if (type .isTypeOrSubTypeOf (Calendar .class )) {
351
301
return JavaUtilCalendarSerializer .instance ;
352
302
}
353
303
if (type .isTypeOrSubTypeOf (Date .class )) {
354
304
// 06-Nov-2020, tatu: Strange precedence challenge; need to consider
355
305
// "java.sql.Date" unfortunately
356
306
if (!type .hasRawClass (Date .class )) {
357
- ValueSerializer <?> ser = OptionalHandlerFactory .instance .findSerializer (ctxt .getConfig (), type );
358
- if (ser != null ) {
307
+ if ((ser = OptionalHandlerFactory .instance .findSerializer (ctxt .getConfig (), type ) ) != null ) {
359
308
return ser ;
360
309
}
361
310
}
@@ -382,12 +331,7 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
382
331
}
383
332
return NumberSerializer .instance ;
384
333
}
385
- if (type .isEnumType ()) {
386
- return buildEnumSerializer (ctxt , type , beanDescRef ,
387
- _calculateEffectiveFormat (beanDescRef , Enum .class , formatOverrides ));
388
- }
389
- Class <?> raw = type .getRawClass ();
390
- if (Map .Entry .class .isAssignableFrom (raw )) {
334
+ if (type .isTypeOrSubTypeOf (Map .Entry .class )) {
391
335
// 18-Oct-2015, tatu: With 2.7, need to dig type info:
392
336
JavaType mapEntryType = type .findSuperType (Map .Entry .class );
393
337
// 28-Apr-2015, tatu: TypeFactory does it all for us already so
0 commit comments