Fix Jackson (hash) mapping for BigDecimal/BigInteger scalar values and Java Time types.
Once again, the SD Redis Jackson2HashMapper can now de/serialize Objects with BigDecimal/BigInteger values along with java.time types, such as java.time.LocalDateTime. Additionally, splits the unit tests for flattening and unflattening of the hash mapping into 2 separate test classes to be picked up in the SD Redis test suite. Resolves #2593
This commit is contained in:
committed by
John Blum
parent
770fbac670
commit
637964eed8
@@ -54,6 +54,7 @@ import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
@@ -183,6 +184,10 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(flatten && t.isTypeOrSubTypeOf(Number.class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EVERYTHING.equals(_appliesFor)) {
|
||||
return !TreeNode.class.isAssignableFrom(t.getRawClass());
|
||||
}
|
||||
@@ -196,6 +201,9 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
|
||||
typingMapper.activateDefaultTyping(typingMapper.getPolymorphicTypeValidator(), DefaultTyping.EVERYTHING,
|
||||
As.PROPERTY);
|
||||
typingMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
|
||||
if(flatten) {
|
||||
typingMapper.disable(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES);
|
||||
}
|
||||
|
||||
// Prevent splitting time types into arrays. E
|
||||
typingMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
@@ -240,7 +248,7 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
|
||||
Map<String, Object> unflattenedHash = doUnflatten(hash);
|
||||
byte[] unflattenedHashedBytes = untypedMapper.writeValueAsBytes(unflattenedHash);
|
||||
Object hashedObject = typingMapper.reader().forType(Object.class)
|
||||
.readValue(unflattenedHashedBytes);;
|
||||
.readValue(unflattenedHashedBytes);
|
||||
|
||||
return hashedObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user