Skip to content

Commit

Permalink
More work towards #4659
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 13, 2024
1 parent 5f08d73 commit 1643c1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class StringArraySerializer

/**
* Value serializer to use, if it's not the standard one
* (if it is we can optimize serialization a lot)
* (if it is we can optimize serialization significantly)
*/
protected final JsonSerializer<Object> _elementSerializer;

Expand Down Expand Up @@ -85,10 +85,9 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
BeanProperty property)
throws JsonMappingException
{
/* 29-Sep-2012, tatu: Actually, we need to do much more contextual
* checking here since we finally know for sure the property,
* and it may have overrides
*/
// 29-Sep-2012, tatu: Actually, we need to do much more contextual
// checking here since we finally know for sure the property,
// and it may have overrides
JsonSerializer<?> ser = null;

// First: if we have a property, may have property-annotation overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
public class StdArraySerializers
{
protected final static HashMap<String, JsonSerializer<?>> _arraySerializers =
new HashMap<String, JsonSerializer<?>>();
new HashMap<>();
static {
// Arrays of various types (including common object types)
_arraySerializers.put(boolean[].class.getName(), new StdArraySerializers.BooleanArraySerializer());
_arraySerializers.put(boolean[].class.getName(), new BooleanArraySerializer());
_arraySerializers.put(byte[].class.getName(), new ByteArraySerializer());
_arraySerializers.put(char[].class.getName(), new StdArraySerializers.CharArraySerializer());
_arraySerializers.put(short[].class.getName(), new StdArraySerializers.ShortArraySerializer());
_arraySerializers.put(int[].class.getName(), new StdArraySerializers.IntArraySerializer());
_arraySerializers.put(long[].class.getName(), new StdArraySerializers.LongArraySerializer());
_arraySerializers.put(float[].class.getName(), new StdArraySerializers.FloatArraySerializer());
_arraySerializers.put(double[].class.getName(), new StdArraySerializers.DoubleArraySerializer());
_arraySerializers.put(char[].class.getName(), new CharArraySerializer());
_arraySerializers.put(short[].class.getName(), new ShortArraySerializer());
_arraySerializers.put(int[].class.getName(), new IntArraySerializer());
_arraySerializers.put(long[].class.getName(), new LongArraySerializer());
_arraySerializers.put(float[].class.getName(), new FloatArraySerializer());
_arraySerializers.put(double[].class.getName(), new DoubleArraySerializer());
}

protected StdArraySerializers() { }
Expand All @@ -46,6 +46,12 @@ public static JsonSerializer<?> findStandardImpl(Class<?> cls) {
return _arraySerializers.get(cls.getName());
}

// @since 2.19
@SuppressWarnings("deprecation")
static JavaType simpleElementType(Class<?> elemClass) {
return TypeFactory.defaultInstance().uncheckedSimpleType(elemClass);
}

/*
****************************************************************
/* Intermediate base classes
Expand Down Expand Up @@ -88,8 +94,7 @@ public static class BooleanArraySerializer
extends ArraySerializerBase<boolean[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Boolean.class);
private final static JavaType VALUE_TYPE = simpleElementType(Boolean.TYPE);

public BooleanArraySerializer() { super(boolean[].class); }

Expand Down Expand Up @@ -179,8 +184,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
public static class ShortArraySerializer extends TypedPrimitiveArraySerializer<short[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Short.TYPE);
private final static JavaType VALUE_TYPE = simpleElementType(Short.TYPE);

public ShortArraySerializer() { super(short[].class); }
public ShortArraySerializer(ShortArraySerializer src, BeanProperty prop,
Expand Down Expand Up @@ -340,8 +344,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
public static class IntArraySerializer extends ArraySerializerBase<int[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Integer.TYPE);
private final static JavaType VALUE_TYPE = simpleElementType(Integer.TYPE);

public IntArraySerializer() { super(int[].class); }

Expand Down Expand Up @@ -429,8 +432,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
public static class LongArraySerializer extends TypedPrimitiveArraySerializer<long[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Long.TYPE);
private final static JavaType VALUE_TYPE = simpleElementType(Long.TYPE);

public LongArraySerializer() { super(long[].class); }
public LongArraySerializer(LongArraySerializer src, BeanProperty prop,
Expand Down Expand Up @@ -508,8 +510,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
public static class FloatArraySerializer extends TypedPrimitiveArraySerializer<float[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Float.TYPE);
private final static JavaType VALUE_TYPE = simpleElementType(Float.TYPE);

public FloatArraySerializer() {
super(float[].class);
Expand Down Expand Up @@ -587,8 +588,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
public static class DoubleArraySerializer extends ArraySerializerBase<double[]>
{
// as above, assuming no one re-defines primitive/wrapper types
@SuppressWarnings("deprecation")
private final static JavaType VALUE_TYPE = TypeFactory.defaultInstance().uncheckedSimpleType(Double.TYPE);
private final static JavaType VALUE_TYPE = simpleElementType(Double.TYPE);

public DoubleArraySerializer() { super(double[].class); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ public static Class<?> rawClass(Type t) {
return rawClass(((WildcardType) t).getUpperBounds()[0]);
}
// fallback
// 12-Oct-2024, tatu: Seems unnecessary (replacing with throw does not
// fail any tests), but left for 2.x, changed in 3.0
return defaultInstance().constructType(t).getRawClass();
}

Expand Down

0 comments on commit 1643c1e

Please sign in to comment.