diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 96eed7fab0..03b0ac175b 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1684,3 +1684,8 @@ Jason Laber (jlaber@github) Andreas Zahnen (azahnen@github) * Reported #4078: `java.desktop` module is no longer optional (2.16.0) + +Omar Aloraini (ooraini@github) + * Requested #4061: Add JsonTypeInfo.Id.SIMPLE_NAME which defaults type id + to `Class.getSimpleName()` + (2.16.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 69d9f222fe..0b0e0983e9 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -56,6 +56,9 @@ Project: jackson-databind #4056: Provide the "ObjectMapper.treeToValue(TreeNode, TypeReference)" method (contributed by @fantasy0v0) #4060: Expose `NativeImageUtil.isRunningInNativeImage()` method +#4061: Add JsonTypeInfo.Id.SIMPLE_NAME which defaults type id to `Class.getSimpleName()` + (requested by Omar A) + (contributed by Joo-Hyuk K) #4071: Impossible to deserialize custom `Throwable` sub-classes that do not have single-String constructors (reported by @PasKal) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SimpleNameIdResolver.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SimpleNameIdResolver.java index 94724f5f64..02837f831b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SimpleNameIdResolver.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SimpleNameIdResolver.java @@ -1,22 +1,22 @@ package com.fasterxml.jackson.databind.jsontype.impl; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.databind.BeanDescription; -import com.fasterxml.jackson.databind.DatabindContext; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.MapperFeature; + +import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.cfg.MapperConfig; import com.fasterxml.jackson.databind.jsontype.NamedType; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; /** * {@link com.fasterxml.jackson.databind.jsontype.TypeIdResolver} implementation - * that converts between (JSON) Strings and simple Java class names. - * + * that converts using explicitly (annotation-) specified type names + * and maps to implementation classes; or, in absence of annotated type name, + * defaults to simple {@link Class} names (obtained with {@link Class#getSimpleName()}. + * Basically same as {@link TypeNameIdResolver} except for default to "simple" + * and not "full" class name. + * * @since 2.16 */ public class SimpleNameIdResolver @@ -161,10 +161,6 @@ protected JavaType _typeFromId(String id) { if (_caseInsensitive) { id = id.toLowerCase(); } - // Now: if no type is found, should we try to locate it by - // some other means? (specifically, if in same package as base type, - // could just try Class.forName) - // For now let's not add any such workarounds; can add if need be return _idToType.get(id); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java index ddf598db57..0fd9ccd931 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java @@ -13,9 +13,9 @@ /** * {@link com.fasterxml.jackson.databind.jsontype.TypeIdResolver} implementation - * that converts uses explicitly specified (by annotation) type names + * that converts using explicitly (annotation-) specified type names * and maps to implementation classes; or, in absence of annotated type name, - * defaults to fully-qualified {@link Class} names. + * defaults to fully-qualified {@link Class} names (obtained with {@link Class#getName()} */ public class TypeNameIdResolver extends TypeIdResolverBase {