diff --git a/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java index e738fe533a..33bbfed94e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java @@ -1,21 +1,32 @@ package com.fasterxml.jackson.databind; -import java.io.IOException; -import java.text.DateFormat; -import java.util.*; - import com.fasterxml.jackson.annotation.ObjectIdGenerator; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.cfg.ContextAttributes; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.ser.*; -import com.fasterxml.jackson.databind.ser.impl.*; +import com.fasterxml.jackson.databind.ser.ContextualSerializer; +import com.fasterxml.jackson.databind.ser.FilterProvider; +import com.fasterxml.jackson.databind.ser.ResolvableSerializer; +import com.fasterxml.jackson.databind.ser.SerializerCache; +import com.fasterxml.jackson.databind.ser.SerializerFactory; +import com.fasterxml.jackson.databind.ser.impl.FailingSerializer; +import com.fasterxml.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap; +import com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer; +import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer; +import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.ser.std.NullSerializer; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.ClassUtil; +import java.io.IOException; +import java.text.DateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + /** * Class that defines API used by {@link ObjectMapper} and * {@link JsonSerializer}s to obtain serializers capable of serializing @@ -722,6 +733,14 @@ public JsonSerializer findTypedValueSerializer(JavaType valueType, boole return ser; } + /** + * Method called to get a Typeserialize to use for accessing Type Information for a given Java class + * Useful for schema generators. + */ + public TypeSerializer findTypeSerializer(JavaType javaType) throws JsonMappingException { + return _serializerFactory.createTypeSerializer(_config, javaType); + } + /** * Method called to get the serializer to use for serializing * non-null Map keys. Separation from regular 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 16224962f8..734cae341f 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 @@ -1,7 +1,5 @@ package com.fasterxml.jackson.databind.jsontype.impl; -import java.util.*; - import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.BeanDescription; import com.fasterxml.jackson.databind.DatabindContext; @@ -9,6 +7,10 @@ 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.TreeSet; + public class TypeNameIdResolver extends TypeIdResolverBase { protected final MapperConfig _config; @@ -80,7 +82,15 @@ public static TypeNameIdResolver construct(MapperConfig config, JavaType base @Override public String idFromValue(Object value) { - Class cls = _typeFactory.constructType(value.getClass()).getRawClass(); + return idFromClass(value.getClass()); + } + + protected String idFromClass(Class clazz) + { + if(clazz==null){ + return null; + } + Class cls = _typeFactory.constructType(clazz).getRawClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { @@ -108,7 +118,7 @@ public String idFromValueAndType(Object value, Class type) { * it seems; nothing much we can figure out that way. */ if (value == null) { - return null; + return idFromClass(type); } return idFromValue(value); }