Fixed [JACKSON-799]
diff --git a/release-notes/VERSION b/release-notes/VERSION
index ac68299..ae666fe 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -13,6 +13,7 @@
(reported by Erik G)
* [JACKSON-794]: JDK 7 has new property for Exceptions ("suppressable"),
needs to be ignored during deserialization
+ * [JACKSON-799]: JsonSerialize.as not working as class annotation, for root values
* [JACKSON-802]: Improvements to class loading to use both contextual
class loader and Class.forName, as necessary
* [JACKSON-803]: Problems with Smile, parsing of long names
diff --git a/src/mapper/java/org/codehaus/jackson/map/ser/BeanSerializerFactory.java b/src/mapper/java/org/codehaus/jackson/map/ser/BeanSerializerFactory.java
index 877f37b..ffe4739 100644
--- a/src/mapper/java/org/codehaus/jackson/map/ser/BeanSerializerFactory.java
+++ b/src/mapper/java/org/codehaus/jackson/map/ser/BeanSerializerFactory.java
@@ -258,6 +258,10 @@
JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType);
// and if so, we consider it implicit "force static typing" instruction
boolean staticTyping = (type != origType);
+ if (type != origType && type.getRawClass() != origType.getRawClass()) {
+ // [JACKSON-799]: need to re-introspect
+ beanDesc = config.introspect(type);
+ }
// Container types differ from non-container types:
if (origType.isContainerType()) {
diff --git a/src/test/org/codehaus/jackson/map/ser/TestAnnotationJsonSerialize2.java b/src/test/org/codehaus/jackson/map/ser/TestAnnotationJsonSerialize2.java
index 84f4a12..9cf1959 100644
--- a/src/test/org/codehaus/jackson/map/ser/TestAnnotationJsonSerialize2.java
+++ b/src/test/org/codehaus/jackson/map/ser/TestAnnotationJsonSerialize2.java
@@ -111,6 +111,31 @@
@JsonSerialize(using=NullSerializer.class)
public String value = "abc";
}
+
+ // [JACKSON-799] stuff:
+
+ public interface Fooable {
+ public int getFoo();
+ }
+
+ // force use of interface
+ @JsonSerialize(as=Fooable.class)
+ public static class FooImpl implements Fooable {
+ public int getFoo() { return 42; }
+ public int getBar() { return 15; }
+ }
+
+ public class FooableWrapper {
+ public FooImpl getFoo() {
+ return new FooImpl();
+ }
+ }
+
+ public void testSerializeAsForSimpleProp() throws IOException
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ assertEquals("{\"foo\":{\"foo\":42}}", mapper.writeValueAsString(new FooableWrapper()));
+ }
/*
/**********************************************************