Skip to content

Commit

Permalink
More clean up after #2478
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 29, 2019
1 parent 479da17 commit 54aa38d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/fasterxml/jackson/databind/JavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public boolean isConcrete() {
public final boolean isEnumType() {
// 29-Sep-2019, tatu: `Class.isEnum()` not enough to detect custom subtypes,
// but for some reason this fix will break couple of unit tests:
// See [databind#2480]:
// return ClassUtil.isEnumType(_class);
return _class.isEnum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ public JsonDeserializer<?> createMapDeserializer(DeserializationContext ctxt,
inst = findValueInstantiator(ctxt, beanDesc);
}
Class<?> kt = keyType.getRawClass();
if (kt == null || !kt.isEnum()) {
if (kt == null || !ClassUtil.isEnumType(kt)) {
throw new IllegalArgumentException("Cannot construct EnumMap; generic (key) type not available");
}
deser = new EnumMapDeserializer(type, inst, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ else if (newType.isAssignableFrom(oldType)) {
* @since 2.8.1
*/
protected boolean _isEnumValueOf(AnnotatedWithParams creator) {
return creator.getDeclaringClass().isEnum()
return ClassUtil.isEnumType(creator.getDeclaringClass())
&& "valueOf".equals(creator.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ClassUtil;

/**
* Standard deserializer for {@link EnumSet}s.
Expand Down Expand Up @@ -50,7 +51,7 @@ public EnumSetDeserializer(JavaType enumType, JsonDeserializer<?> deser)
_enumType = enumType;
_enumClass = (Class<Enum>) enumType.getRawClass();
// sanity check
if (!_enumClass.isEnum()) {
if (!ClassUtil.isEnumType(_enumClass)) {
throw new IllegalArgumentException("Type "+enumType+" not Java Enum type");
}
_enumDeserializer = (JsonDeserializer<Enum<?>>) deser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public Object deserializeKey(String key, DeserializationContext ctxt)
re.getClass().getName(),
ClassUtil.exceptionMessage(re));
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
if (ClassUtil.isEnumType(_keyClass)
&& ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ protected AnnotatedConstructor constructNonDefaultConstructor(ClassUtil.Ctor cto
resolvedAnnotations = null;
Class<?> dc = ctor.getDeclaringClass();
// (a) is enum, which have two extra hidden params (name, index)
if (dc.isEnum() && (paramCount == paramAnns.length + 2)) {
if (ClassUtil.isEnumType(dc) && (paramCount == paramAnns.length + 2)) {
Annotation[][] old = paramAnns;
paramAnns = new Annotation[old.length+2][];
System.arraycopy(old, 0, paramAnns, 2, old.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ protected String _idFrom(Object value, Class<?> cls, TypeFactory typeFactory)
{
// Need to ensure that "enum subtypes" work too
if (ClassUtil.isEnumType(cls)) {
if (!cls.isEnum()) { // means that it's sub-class of base enum, so:
// 29-Sep-2019, tatu: `Class.isEnum()` only returns true for main declaration,
// but NOT from sub-class thereof (extending individual values). This
// is why additional resolution is needed: we want class that contains
// enumeration instances.
if (!cls.isEnum()) {
// and this parent would then have `Enum.class` as its parent:
cls = cls.getSuperclass();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.ser.impl.PropertyBasedObjectIdGenerator;
import com.fasterxml.jackson.databind.ser.impl.WritableObjectId;
import com.fasterxml.jackson.databind.util.ArrayBuilders;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
import com.fasterxml.jackson.databind.util.NameTransformer;

Expand Down Expand Up @@ -425,7 +426,7 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
shape = format.getShape();
// or, alternatively, asked to revert "back to" other representations...
if ((shape != JsonFormat.Shape.ANY) && (shape != _serializationShape)) {
if (_handledType.isEnum()) {
if (ClassUtil.isEnumType(_handledType)) {
switch (shape) {
case STRING:
case NUMBER:
Expand Down

0 comments on commit 54aa38d

Please sign in to comment.