Skip to content

Commit 92ec550

Browse files
committed
Merge branch '2.19' into 2.x
2 parents f335ab2 + b29d3ab commit 92ec550

File tree

4 files changed

+179
-5
lines changed

4 files changed

+179
-5
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/EnumMapDeserializer.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,18 @@ public EnumMap<?,?> deserialize(JsonParser p, DeserializationContext ctxt,
308308
if (_skipNullValues) {
309309
continue;
310310
}
311-
value = _nullProvider.getNullValue(ctxt);
311+
value = null;
312312
} else {
313313
value = _deserializeNoNullChecks(p, ctxt);
314314
}
315+
316+
if (value == null) {
317+
value = _nullProvider.getNullValue(ctxt);
318+
319+
if (value == null && _skipNullValues) {
320+
continue;
321+
}
322+
}
315323
} catch (Exception e) {
316324
return wrapAndThrow(ctxt, e, result, keyStr);
317325
}
@@ -400,10 +408,18 @@ public EnumMap<?,?> _deserializeUsingProperties(JsonParser p, DeserializationCon
400408
if (_skipNullValues) {
401409
continue;
402410
}
403-
value = _nullProvider.getNullValue(ctxt);
411+
value = null;
404412
} else {
405413
value = _deserializeNoNullChecks(p, ctxt);
406414
}
415+
416+
if (value == null) {
417+
value = _nullProvider.getNullValue(ctxt);
418+
419+
if (value == null && _skipNullValues) {
420+
continue;
421+
}
422+
}
407423
} catch (Exception e) {
408424
wrapAndThrow(ctxt, e, _containerType.getRawClass(), keyName);
409425
return null;

src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,19 @@ protected final Map<Object,Object> _readAndBind(JsonParser p, DeserializationCon
547547
if (_skipNullValues) {
548548
continue;
549549
}
550-
value = _nullProvider.getNullValue(ctxt);
550+
value = null;
551551
} else {
552552
value = _deserializeNoNullChecks(p, ctxt);
553553
}
554+
555+
if (value == null) {
556+
value = _nullProvider.getNullValue(ctxt);
557+
558+
if (value == null && _skipNullValues) {
559+
continue;
560+
}
561+
}
562+
554563
if (useObjectId) {
555564
referringAccumulator.put(key, value);
556565
} else {
@@ -609,10 +618,19 @@ protected final Map<Object,Object> _readAndBindStringKeyMap(JsonParser p, Deseri
609618
if (_skipNullValues) {
610619
continue;
611620
}
612-
value = _nullProvider.getNullValue(ctxt);
621+
value = null;
613622
} else {
614623
value = _deserializeNoNullChecks(p, ctxt);
615624
}
625+
626+
if (value == null) {
627+
value = _nullProvider.getNullValue(ctxt);
628+
629+
if (value == null && _skipNullValues) {
630+
continue;
631+
}
632+
}
633+
616634
if (useObjectId) {
617635
referringAccumulator.put(key, value);
618636
} else {
@@ -679,10 +697,18 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser p, Deserialization
679697
if (_skipNullValues) {
680698
continue;
681699
}
682-
value = _nullProvider.getNullValue(ctxt);
700+
value = null;
683701
} else {
684702
value = _deserializeNoNullChecks(p, ctxt);
685703
}
704+
705+
if (value == null) {
706+
value = _nullProvider.getNullValue(ctxt);
707+
708+
if (value == null && _skipNullValues) {
709+
continue;
710+
}
711+
}
686712
} catch (Exception e) {
687713
wrapAndThrow(ctxt, e, _containerType.getRawClass(), key);
688714
return null;
@@ -759,6 +785,15 @@ protected final void _readAndUpdate(JsonParser p, DeserializationContext ctxt,
759785
} else {
760786
value = _deserializeNoNullChecks(p, ctxt);
761787
}
788+
789+
if (value == null) {
790+
value = _nullProvider.getNullValue(ctxt);
791+
792+
if (value == null && _skipNullValues) {
793+
continue;
794+
}
795+
}
796+
762797
if (value != old) {
763798
result.put(key, value);
764799
}
@@ -824,6 +859,15 @@ protected final void _readAndUpdateStringKeyMap(JsonParser p, DeserializationCon
824859
} else {
825860
value = _deserializeNoNullChecks(p, ctxt);
826861
}
862+
863+
if (value == null) {
864+
value = _nullProvider.getNullValue(ctxt);
865+
866+
if (value == null && _skipNullValues) {
867+
continue;
868+
}
869+
}
870+
827871
if (value != old) {
828872
result.put(key, value);
829873
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.fasterxml.jackson.databind.deser.jdk;
2+
3+
import java.util.EnumMap;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonSetter;
8+
import com.fasterxml.jackson.annotation.Nulls;
9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.exc.InvalidNullException;
12+
import com.fasterxml.jackson.databind.json.JsonMapper;
13+
import org.opentest4j.AssertionFailedError;
14+
15+
import static org.junit.jupiter.api.Assertions.assertFalse;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
19+
// For [databind#5165]
20+
public class EnumMapDeserializer5165Test
21+
{
22+
public enum MyEnum {
23+
FOO
24+
}
25+
26+
static class Dst {
27+
private EnumMap<MyEnum, Integer> map;
28+
29+
public EnumMap<MyEnum, Integer> getMap() {
30+
return map;
31+
}
32+
33+
public void setMap(EnumMap<MyEnum, Integer> map) {
34+
this.map = map;
35+
}
36+
}
37+
38+
@Test
39+
public void nullsFailTest() {
40+
ObjectMapper mapper = JsonMapper.builder()
41+
.defaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.FAIL))
42+
.build();
43+
44+
assertThrows(
45+
InvalidNullException.class,
46+
() -> mapper.readValue("{\"map\":{\"FOO\":\"\"}}", new TypeReference<Dst>(){})
47+
);
48+
}
49+
50+
@Test
51+
public void nullsSkipTest() throws Exception {
52+
ObjectMapper mapper = JsonMapper.builder()
53+
.defaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.SKIP))
54+
.build();
55+
56+
Dst dst = mapper.readValue("{\"map\":{\"FOO\":\"\"}}", new TypeReference<Dst>() {});
57+
58+
assertTrue(dst.getMap().isEmpty());
59+
}
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fasterxml.jackson.databind.deser.jdk;
2+
3+
import java.util.Map;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonSetter;
8+
import com.fasterxml.jackson.annotation.Nulls;
9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.exc.InvalidNullException;
12+
import com.fasterxml.jackson.databind.json.JsonMapper;
13+
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
17+
// For [databind#5165]
18+
public class MapDeserializer5165Test
19+
{
20+
static class Dst {
21+
private Map<String, Integer> map;
22+
23+
public Map<String, Integer> getMap() {
24+
return map;
25+
}
26+
27+
public void setMap(Map<String, Integer> map) {
28+
this.map = map;
29+
}
30+
}
31+
32+
@Test
33+
public void nullsFailTest() {
34+
ObjectMapper mapper = JsonMapper.builder()
35+
.defaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.FAIL))
36+
.build();
37+
38+
assertThrows(
39+
InvalidNullException.class,
40+
() -> mapper.readValue("{\"map\":{\"key\":\"\"}}", new TypeReference<Dst>(){})
41+
);
42+
}
43+
44+
@Test
45+
public void nullsSkipTest() throws Exception {
46+
ObjectMapper mapper = JsonMapper.builder()
47+
.defaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.SKIP))
48+
.build();
49+
50+
Dst dst = mapper.readValue("{\"map\":{\"key\":\"\"}}", new TypeReference<Dst>() {});
51+
52+
assertTrue(dst.getMap().isEmpty());
53+
}
54+
}

0 commit comments

Comments
 (0)