Skip to content

Commit

Permalink
Fix #1600 (for 3.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 15, 2018
1 parent b46230c commit ebe7d44
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 207 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ Version numbers in brackets indicate release in which the problem was fixed
(note: for older credits, see `CREDITS-2.x` instead)

Tatu Saloranta, [email protected]: author

Alexander Koshman (akoshman@github)
* Requested #1600: Serializing locale with underscore, not standard hyphen
[3.0.0]
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Versions: 3.x (for earlier see VERSION-2.x)

#1058: Add a way to pass std and format-specific parser/generator flags during
parser/generation construction
#1600: Serializing locale with underscore, not standard hyphen
(requested by Alexander K)
#1762: `StdDateFormat`: serialize time offset using colon
#1772: Remove `MapperFeature. USE_STD_BEAN_NAMING`
#1773: Remove `MapperFeature.AUTO_DETECT_xxx` features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ public class StdJdkDeserializers
private final static HashSet<String> _classNames = new HashSet<String>();
static {
// note: can skip primitive types; other ways to check them:
Class<?>[] types = new Class<?>[] {
UUID.class,
AtomicBoolean.class,
StackTraceElement.class,
ByteBuffer.class
};
for (Class<?> cls : types) { _classNames.add(cls.getName()); }
for (Class<?> cls : FromStringDeserializer.types()) { _classNames.add(cls.getName()); }
_classNames.add(UUID.class.getName());
_classNames.add(AtomicBoolean.class.getName());
_classNames.add(StackTraceElement.class.getName());
_classNames.add(ByteBuffer.class.getName());
for (Class<?> cls : FromStringDeserializer.types()) {
_classNames.add(cls.getName());
}
}

public static JsonDeserializer<?> find(Class<?> rawType, String clsName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public abstract class BasicSerializerFactory
implements java.io.Serializable
{
/*
/**********************************************************
/**********************************************************************
/* Configuration, lookup tables/maps
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -63,25 +63,16 @@ public abstract class BasicSerializerFactory
* use the class name, and keep things simple and efficient.
*/
protected final static HashMap<String, JsonSerializer<?>> _concrete;

/**
* Actually it may not make much sense to eagerly instantiate all
* kinds of serializers: so this Map actually contains class references,
* not instances
*/
protected final static HashMap<String, Class<? extends JsonSerializer<?>>> _concreteLazy;

static {
HashMap<String, Class<? extends JsonSerializer<?>>> concLazy
= new HashMap<String, Class<? extends JsonSerializer<?>>>();
HashMap<String, JsonSerializer<?>> concrete
= new HashMap<String, JsonSerializer<?>>();


/* String and string-like types (note: date types explicitly
* not included -- can use either textual or numeric serialization)
*/
concrete.put(String.class.getName(), new StringSerializer());
concrete.put(String.class.getName(), StringSerializer.instance);
final ToStringSerializer sls = ToStringSerializer.instance;
concrete.put(StringBuffer.class.getName(), sls);
concrete.put(StringBuilder.class.getName(), sls);
Expand All @@ -95,37 +86,20 @@ public abstract class BasicSerializerFactory

// Other numbers, more complicated
concrete.put(BigInteger.class.getName(), new NumberSerializer(BigInteger.class));
concrete.put(BigDecimal.class.getName(),new NumberSerializer(BigDecimal.class));
concrete.put(BigDecimal.class.getName(), new NumberSerializer(BigDecimal.class));

// Other discrete non-container types:
// First, Date/Time zoo:
concrete.put(Calendar.class.getName(), CalendarSerializer.instance);
concrete.put(java.util.Date.class.getName(), DateSerializer.instance);

// And then other standard non-structured JDK types
for (Map.Entry<Class<?>,Object> en : StdJdkSerializers.all()) {
Object value = en.getValue();
if (value instanceof JsonSerializer<?>) {
concrete.put(en.getKey().getName(), (JsonSerializer<?>) value);
} else {
@SuppressWarnings("unchecked")
Class<? extends JsonSerializer<?>> cls = (Class<? extends JsonSerializer<?>>) value;
concLazy.put(en.getKey().getName(), cls);
}
}

// Jackson-specific type(s)
// (Q: can this ever be sub-classed?)
concLazy.put(TokenBuffer.class.getName(), TokenBufferSerializer.class);

_concrete = concrete;
_concreteLazy = concLazy;
}

/*
/**********************************************************
/**********************************************************************
/* Configuration
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -315,17 +289,11 @@ protected final JsonSerializer<?> findSerializerByLookup(JavaType type,
SerializationConfig config, BeanDescription beanDesc,
boolean staticTyping)
{
Class<?> raw = type.getRawClass();
String clsName = raw.getName();
JsonSerializer<?> ser = _concrete.get(clsName);
final Class<?> raw = type.getRawClass();
JsonSerializer<?> ser = StdJdkSerializers.find(raw);
if (ser == null) {
Class<? extends JsonSerializer<?>> serClass = _concreteLazy.get(clsName);
if (serClass != null) {
// 07-Jan-2017, tatu: Should never fail (since we control constructors),
// but if it does will throw `IllegalArgumentException` with description,
// which we could catch, re-title.
return ClassUtil.createInstance(serClass, false);
}
final String clsName = raw.getName();
ser = _concrete.get(clsName);
}
return ser;
}
Expand All @@ -343,8 +311,6 @@ protected final JsonSerializer<?> findSerializerByLookup(JavaType type,
* based on that property
* </li>
*</ul>
*
* @since 2.0
*/
protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider prov,
JavaType type, BeanDescription beanDesc)
Expand Down Expand Up @@ -447,10 +413,10 @@ protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider
if (DoubleStream.class.isAssignableFrom(raw)) {
return DoubleStreamSerializer.INSTANCE;
}
// 17-Sep-2017, tatu: With 3.0, this JDK7 type may be added here too.
// NOTE: not concrete, can not just add via StdJdkSerializers.
// NOTE: not concrete, can not just add directly via StdJdkSerializers. Also, requires
// bit of trickery wrt class name for polymorphic...
if (Path.class.isAssignableFrom(raw)) {
return new NioPathSerializer();
return StringLikeSerializer.find(Path.class);
}
// Then check for optional/external serializers
JsonSerializer<?> ser = OptionalHandlerFactory.instance.findSerializer(prov.getConfig(),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ebe7d44

Please sign in to comment.