Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow ups from FasterXML/jackson-databind#838 #855

Merged
merged 1 commit into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -722,6 +733,14 @@ public JsonSerializer<Object> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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;
import com.fasterxml.jackson.databind.JavaType;
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down