Skip to content

Commit fcb0095

Browse files
hjikp p
1 parent 5f30515 commit fcb0095

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

src/main/java/org/springframework/data/redis/hash/Jackson3HashMapper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public class Jackson3HashMapper implements HashMapper<Object, String, Object> {
160160
Jackson3HashMapper.class.getClassLoader());
161161

162162
private final ObjectMapper typingMapper;
163+
private final ObjectMapper untypedMapper;
163164
private final boolean flatten;
164165

165166
public Jackson3HashMapper(
@@ -178,6 +179,7 @@ public static void preconfigure(MapperBuilder<? extends ObjectMapper, ? extends
178179
.allowIfSubType((ctx, clazz) -> true).build(), DefaultTyping.NON_FINAL_AND_ENUMS, "@class")
179180
.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false)
180181
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
182+
//.configure(DeserializationFeature., false)
181183
.changeDefaultPropertyInclusion(value -> value.withValueInclusion(Include.NON_NULL));
182184
}
183185

@@ -195,14 +197,15 @@ public Jackson3HashMapper(ObjectMapper mapper, boolean flatten) {
195197

196198
this.flatten = flatten;
197199
this.typingMapper = mapper;
200+
this.untypedMapper = mapper.rebuild().deactivateDefaultTyping().build();
198201
}
199202

200203
@Override
201204
@SuppressWarnings("unchecked")
202205
public Map<String, Object> toHash(Object source) {
203206

204207
JsonNode tree = this.typingMapper.valueToTree(source);
205-
return this.flatten ? flattenMap(tree.properties()) : JsonMapper.shared().convertValue(tree, Map.class);
208+
return this.flatten ? flattenMap(tree.properties()) : this.untypedMapper.convertValue(tree, Map.class);
206209
}
207210

208211
@Override
@@ -213,13 +216,14 @@ public Object fromHash(Map<String, Object> hash) {
213216
if (this.flatten) {
214217

215218
Map<String, Object> unflattenedHash = doUnflatten(hash);
216-
byte[] unflattenedHashedBytes = JsonMapper.shared().writeValueAsBytes(unflattenedHash);
219+
System.out.println("unflat: " + unflattenedHash);
220+
byte[] unflattenedHashedBytes = this.untypedMapper.writeValueAsBytes(unflattenedHash);
217221
Object hashedObject = this.typingMapper.reader().forType(Object.class).readValue(unflattenedHashedBytes);
218222

219223
return hashedObject;
220224
}
221225

222-
return this.typingMapper.treeToValue(JsonMapper.shared().valueToTree(hash), Object.class);
226+
return this.typingMapper.treeToValue(this.untypedMapper.valueToTree(hash), Object.class);
223227

224228
} catch (Exception ex) {
225229
throw new MappingException(ex.getMessage(), ex);

src/test/java/org/springframework/data/redis/mapping/AbstractHashMapperTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected void assertBackAndForwardMapping(Object o) {
3939

4040
HashMapper mapper = mapperFor(o.getClass());
4141
Map hash = mapper.toHash(o);
42+
System.out.println("hash: " + hash);
4243
assertThat(mapper.fromHash(hash)).isEqualTo(o);
4344
}
4445

src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperFlatteningUnitTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Map;
2323

2424
import org.junit.jupiter.api.Test;
25-
import org.springframework.data.redis.hash.Jackson2HashMapper;
2625
import org.springframework.data.redis.hash.Jackson3HashMapper;
2726

2827
/**
@@ -33,7 +32,7 @@
3332
public class Jackson3HashMapperFlatteningUnitTests extends Jackson3HashMapperUnitTests {
3433

3534
Jackson3HashMapperFlatteningUnitTests() {
36-
super(new Jackson3HashMapper(Jackson3HashMapper::preconfigure, true), new Jackson2HashMapper(true));
35+
super(new Jackson3HashMapper(Jackson3HashMapper::preconfigure,true));
3736
}
3837

3938
@Test // GH-2593

src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperNonFlatteningUnitTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Map;
2323

2424
import org.junit.jupiter.api.Test;
25-
import org.springframework.data.redis.hash.Jackson2HashMapper;
2625
import org.springframework.data.redis.hash.Jackson3HashMapper;
2726

2827
/**
@@ -33,7 +32,7 @@
3332
public class Jackson3HashMapperNonFlatteningUnitTests extends Jackson3HashMapperUnitTests {
3433

3534
Jackson3HashMapperNonFlatteningUnitTests() {
36-
super(new Jackson3HashMapper(Jackson3HashMapper::preconfigure, false), new Jackson2HashMapper(false));
35+
super(new Jackson3HashMapper(Jackson3HashMapper::preconfigure, false));
3736
}
3837

3938
@Test // GH-2593

src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperUnitTests.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.redis.mapping;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
2018
import java.math.BigDecimal;
2119
import java.math.BigInteger;
2220
import java.time.LocalDate;
@@ -48,12 +46,10 @@
4846
public abstract class Jackson3HashMapperUnitTests extends AbstractHashMapperTests {
4947

5048
private final Jackson3HashMapper mapper;
51-
private final Jackson2HashMapper legacyMapper;
5249

53-
public Jackson3HashMapperUnitTests(Jackson3HashMapper mapper, Jackson2HashMapper legacyMapper) {
50+
public Jackson3HashMapperUnitTests(Jackson3HashMapper mapper) {
5451

5552
this.mapper = mapper;
56-
this.legacyMapper = legacyMapper;
5753
}
5854

5955
protected Jackson3HashMapper getMapper() {
@@ -66,21 +62,6 @@ protected <T> HashMapper mapperFor(Class<T> t) {
6662
return getMapper();
6763
}
6864

69-
protected void assertBackAndForwardMapping(Object o) {
70-
71-
super.assertBackAndForwardMapping(o);
72-
assertLegacyMapperCompatibility(o);
73-
}
74-
75-
protected void assertLegacyMapperCompatibility(Object o) {
76-
77-
Map hash1 = legacyMapper.toHash(o);
78-
assertThat(mapper.fromHash(hash1)).isEqualTo(o);
79-
80-
Map hash2 = mapper.toHash(o);
81-
assertThat(legacyMapper.fromHash(hash2)).isEqualTo(o);
82-
}
83-
8465
@Test // DATAREDIS-423
8566
void shouldMapTypedListOfSimpleType() {
8667

0 commit comments

Comments
 (0)