diff --git a/release-notes/VERSION b/release-notes/VERSION index 709200082e..81eece8554 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -8,6 +8,8 @@ Version: 2.3.2 (xx-xxx-2014) (reported by Chris P, cpilsworth@github) #398: Should deserialize empty (not null) URI from empty String (reported by pgieser@github) +#406: @JsonTypeIdResolver not working with external type ids + (repoted by Martin T) - Added `BeanSerializerBase._serializeObjectId()` needed by modules that override standard BeanSerializer; specifically, XML module. diff --git a/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeIdResolver.java b/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeIdResolver.java index c8d0f4f37f..8aa41cb522 100644 --- a/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeIdResolver.java +++ b/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeIdResolver.java @@ -18,8 +18,11 @@ * for converting between java types and type id included in JSON content. * In simplest cases this can be a simple class with static mapping between * type names and matching classes. + *
+ * NOTE: since 2.4, applicable to properties as well (should have been long time + * ago, but problem only found then) */ -@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) +@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonTypeIdResolver diff --git a/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeResolver.java b/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeResolver.java index 53156d29b5..b46e0aa715 100644 --- a/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeResolver.java +++ b/src/main/java/com/fasterxml/jackson/databind/annotation/JsonTypeResolver.java @@ -9,8 +9,11 @@ * used for handling serialization and deserialization of type information, * needed for handling of polymorphic types (or sometimes just for linking * abstract types to concrete types) + *
+ * NOTE: since 2.4, applicable to properties as well (should have been long time
+ * ago, but problem only found then)
*/
-@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
+@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
public @interface JsonTypeResolver
diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestCustomTypeIdResolver.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestCustomTypeIdResolver.java
index 0a4caddfe9..98b3d91ac4 100644
--- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestCustomTypeIdResolver.java
+++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestCustomTypeIdResolver.java
@@ -17,28 +17,66 @@ public class TestCustomTypeIdResolver extends BaseMapTest
{
@JsonTypeInfo(use=Id.CUSTOM, include=As.WRAPPER_OBJECT)
@JsonTypeIdResolver(CustomResolver.class)
- static class CustomBean {
+ static abstract class CustomBean { }
+
+ static class CustomBeanImpl extends CustomBean {
public int x;
- public CustomBean() { }
- public CustomBean(int x) { this.x = x; }
+ public CustomBeanImpl() { }
+ public CustomBeanImpl(int x) { this.x = x; }
}
-
- static class CustomResolver implements TypeIdResolver
- {
+
+ static class ExtBeanWrapper {
+ @JsonTypeInfo(use=Id.CUSTOM, include=As.EXTERNAL_PROPERTY, property="type")
+ @JsonTypeIdResolver(ExtResolver.class)
+ public ExtBean value;
+ }
+
+ static class CustomResolver extends CustomResolverBase {
+ // yes, static: just for test purposes, not real use
static List