Fix error deserializing enum values with flattening Jackson2HashMapper.
This commit makes sure the mapper does not attempt to read type alias when deserializing enums. Original pull request: #2980 Closes #2979
This commit is contained in:
committed by
Mark Paluch
parent
7a39c5c1fe
commit
5909a491dc
@@ -177,7 +177,7 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flatten && type.isTypeOrSubTypeOf(Number.class)) {
|
||||
if (flatten && (type.isTypeOrSubTypeOf(Number.class) || type.isEnumType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,15 @@ public abstract class Jackson2HashMapperUnitTests extends AbstractHashMapperTest
|
||||
assertBackAndForwardMapping(source);
|
||||
}
|
||||
|
||||
@Test // GH-2979
|
||||
void enumsShouldBeTreatedCorrectly() {
|
||||
|
||||
WithEnumValue source = new WithEnumValue();
|
||||
source.value = SpringDataEnum.REDIS;
|
||||
|
||||
assertBackAndForwardMapping(source);
|
||||
}
|
||||
|
||||
public static class WithList {
|
||||
|
||||
List<String> strings;
|
||||
@@ -452,4 +461,38 @@ public abstract class Jackson2HashMapperUnitTests extends AbstractHashMapperTest
|
||||
return Objects.hash(getValue());
|
||||
}
|
||||
}
|
||||
|
||||
enum SpringDataEnum {
|
||||
COMMONS, REDIS
|
||||
}
|
||||
|
||||
static class WithEnumValue {
|
||||
|
||||
SpringDataEnum value;
|
||||
|
||||
public SpringDataEnum getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SpringDataEnum value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
WithEnumValue that = (WithEnumValue) o;
|
||||
return value == that.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user