File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
main/java/com/fasterxml/jackson/module/scala/deser
test/scala/com/fasterxml/jackson/module/scala/deser Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .fasterxml .jackson .module .scala .deser ;
2
2
3
3
import com .fasterxml .jackson .databind .DeserializationContext ;
4
+ import com .fasterxml .jackson .databind .DeserializationFeature ;
4
5
import com .fasterxml .jackson .databind .JavaType ;
5
6
import com .fasterxml .jackson .databind .JsonMappingException ;
6
7
import com .fasterxml .jackson .databind .deser .std .ContainerDeserializerBase ;
@@ -16,6 +17,10 @@ protected ContainerDeserializerWithNullValueAsEmpty(JavaType selfType) {
16
17
17
18
@ Override
18
19
public T getNullValue (DeserializationContext ctxt ) throws JsonMappingException {
19
- return (T ) getEmptyValue (ctxt );
20
+ if (ctxt .isEnabled (DeserializationFeature .FAIL_ON_NULL_CREATOR_PROPERTIES )) {
21
+ return super .getNullValue (ctxt );
22
+ } else {
23
+ return (T ) getEmptyValue (ctxt );
24
+ }
20
25
}
21
26
}
Original file line number Diff line number Diff line change @@ -207,6 +207,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
207
207
result.list shouldBe List .empty
208
208
}
209
209
210
+ it should " fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
211
+ val input = """ {}"""
212
+ val mapper = newBuilder.enable(DeserializationFeature .FAIL_ON_NULL_CREATOR_PROPERTIES ).build()
213
+ intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException ] {
214
+ mapper.readValue(input, classOf [ListHolder [String ]])
215
+ }
216
+ }
217
+
210
218
it should " support deserializing null input for list as empty list (JsonSetter annotation)" in {
211
219
val input = """ {}"""
212
220
val result = deserialize(input, classOf [AnnotatedListHolder [String ]])
@@ -231,4 +239,13 @@ class CaseClassDeserializerTest extends DeserializerTest {
231
239
// result.map used to be null until v2.19.0
232
240
result.map shouldBe Map .empty
233
241
}
242
+
243
+ it should " fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
244
+ val input = """ {}"""
245
+ val mapper = newBuilder.enable(DeserializationFeature .FAIL_ON_NULL_CREATOR_PROPERTIES ).build()
246
+ intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException ] {
247
+ mapper.readValue(input, classOf [MapHolder [Int , String ]])
248
+ }
249
+ }
250
+
234
251
}
You can’t perform that action at this time.
0 commit comments