@@ -67,7 +67,7 @@ public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
67
67
_values = v ;
68
68
_serializeAsIndex = serializeAsIndex ;
69
69
}
70
-
70
+
71
71
/**
72
72
* Factory method used by {@link com.fasterxml.jackson.databind.ser.BasicSerializerFactory}
73
73
* for constructing serializer instance of Enum types.
@@ -83,7 +83,7 @@ public static EnumSerializer construct(Class<?> enumClass, SerializationConfig c
83
83
* handle toString() case dynamically (for example)
84
84
*/
85
85
EnumValues v = EnumValues .constructFromName (config , (Class <Enum <?>>) enumClass );
86
- Boolean serializeAsIndex = _isShapeWrittenUsingIndex (enumClass , format , true );
86
+ Boolean serializeAsIndex = _isShapeWrittenUsingIndex (enumClass , format , true , null );
87
87
return new EnumSerializer (v , serializeAsIndex );
88
88
}
89
89
@@ -100,7 +100,8 @@ public JsonSerializer<?> createContextual(SerializerProvider serializers,
100
100
JsonFormat .Value format = findFormatOverrides (serializers ,
101
101
property , handledType ());
102
102
if (format != null ) {
103
- Boolean serializeAsIndex = _isShapeWrittenUsingIndex (property .getType ().getRawClass (), format , false );
103
+ Boolean serializeAsIndex = _isShapeWrittenUsingIndex (property .getType ().getRawClass (),
104
+ format , false , _serializeAsIndex );
104
105
if (serializeAsIndex != _serializeAsIndex ) {
105
106
return new EnumSerializer (_values , serializeAsIndex );
106
107
}
@@ -209,18 +210,20 @@ protected final boolean _serializeAsIndex(SerializerProvider serializers)
209
210
}
210
211
211
212
/**
212
- * Helper method called to check whether
213
+ * Helper method called to check whether serialization should be done using
214
+ * index (number) or not.
213
215
*/
214
216
protected static Boolean _isShapeWrittenUsingIndex (Class <?> enumClass ,
215
- JsonFormat .Value format , boolean fromClass )
217
+ JsonFormat .Value format , boolean fromClass ,
218
+ Boolean defaultValue )
216
219
{
217
220
JsonFormat .Shape shape = (format == null ) ? null : format .getShape ();
218
221
if (shape == null ) {
219
- return null ;
222
+ return defaultValue ;
220
223
}
221
224
// i.e. "default", check dynamically
222
225
if (shape == Shape .ANY || shape == Shape .SCALAR ) {
223
- return null ;
226
+ return defaultValue ;
224
227
}
225
228
// 19-May-2016, tatu: also consider "natural" shape
226
229
if (shape == Shape .STRING || shape == Shape .NATURAL ) {
@@ -230,9 +233,9 @@ protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass,
230
233
if (shape .isNumeric () || (shape == Shape .ARRAY )) {
231
234
return Boolean .TRUE ;
232
235
}
233
- throw new IllegalArgumentException ( "Unsupported serialization shape (" + shape + ") for Enum " + enumClass . getName ()
234
- + ", not supported as "
235
- + ( fromClass ? "class" : "property" )
236
- + " annotation" );
236
+ // 07-Mar-2017, tatu: Also means `OBJECT` not available as property annotation...
237
+ throw new IllegalArgumentException ( String . format (
238
+ "Unsupported serialization shape (%s) for Enum %s, not supported as %s annotation" ,
239
+ shape , enumClass . getName (), ( fromClass ? "class" : "property" )) );
237
240
}
238
241
}
0 commit comments