Fixed [JACKSON-875], enum value handling wrong if USE_ANNOTATIONS disabled
diff --git a/release-notes/CREDITS b/release-notes/CREDITS index c69cbcb..1187dd0 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS
@@ -903,6 +903,9 @@ Laurent Pireyn: * Reported [JACKSON-831] External type id, explicit property do not work well together [1.9.7] + * Reported [JACKSON-875]: Enums are not properly serialized when + Feature.USE_ANNOTATIONS is disabled + [1.9.12] Jan Jan: * Reported [JACKSON-832] (partial) Fix numeric range check for Longs (was not working)
diff --git a/release-notes/VERSION b/release-notes/VERSION index e921fe2..04d4733 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION
@@ -8,12 +8,20 @@ Fixes: -* [Issue#8]: Problem with 'SmileGenerator', addSeenName() +* [JACKSON-875]: Enums are not properly serialized when + Feature.USE_ANNOTATIONS is disabled + (reported by Laurent P) ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ +1.9.11 (06-Nov-2012) + +Fixes: + +* [Issue#8]: Problem with 'SmileGenerator', addSeenName() + 1.9.10 (23-Sep-2012) Fixes:
diff --git a/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java b/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java index 9c146de..a8856ba 100644 --- a/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java +++ b/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java
@@ -637,10 +637,15 @@ * Method for determining the String value to use for serializing * given enumeration entry; used when serializing enumerations * as Strings (the standard method). + *<p> + * NOTE: implemented since 1.9.11, to make things work even when + * annotation introspection is disabled. * * @return Serialized enum value. */ - public abstract String findEnumValue(Enum<?> value); + public String findEnumValue(Enum<?> value) { + return value.name(); + } /* /**********************************************************
diff --git a/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java b/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java index 72012c1..883a61f 100644 --- a/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java +++ b/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java
@@ -42,7 +42,8 @@ @Override public String findEnumValue(Enum<?> value) { - return null; + // as per [JACKSON-875] + return value.name(); } /*
diff --git a/src/test/org/codehaus/jackson/map/deser/TestConfig.java b/src/test/org/codehaus/jackson/map/deser/TestConfig.java index e6ef9d5..346526f 100644 --- a/src/test/org/codehaus/jackson/map/deser/TestConfig.java +++ b/src/test/org/codehaus/jackson/map/deser/TestConfig.java
@@ -22,6 +22,8 @@ @JsonProperty("y") public void setX(int v) { value = v; } } + + enum Alpha { A, B, C; } /* /********************************************************** @@ -115,4 +117,16 @@ mapper.getDeserializerProvider().flushCachedDeserializers(); assertEquals(0, mapper.getDeserializerProvider().cachedDeserializersCount()); } + + // [JACKSON-875] + public void testEnumsWhenDisabled() throws Exception + { + ObjectMapper m = new ObjectMapper(); + assertEquals(Alpha.B, m.readValue(quote("B"), Alpha.class)); + + m = new ObjectMapper(); + m.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false); + // should still use the basic name handling here + assertEquals(Alpha.B, m.readValue(quote("B"), Alpha.class)); + } }