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 @@ -206,6 +206,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
206
206
result.list shouldBe List .empty
207
207
}
208
208
209
+ it should " fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
210
+ val input = """ {}"""
211
+ val mapper = newBuilder.enable(DeserializationFeature .FAIL_ON_NULL_CREATOR_PROPERTIES ).build()
212
+ intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException ] {
213
+ mapper.readValue(input, classOf [ListHolder [String ]])
214
+ }
215
+ }
216
+
209
217
it should " support deserializing null input for list as empty list (JsonSetter annotation)" in {
210
218
val input = """ {}"""
211
219
val result = deserialize(input, classOf [AnnotatedListHolder [String ]])
@@ -218,4 +226,13 @@ class CaseClassDeserializerTest extends DeserializerTest {
218
226
// result.map used to be null until v2.19.0
219
227
result.map shouldBe Map .empty
220
228
}
229
+
230
+ it should " fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
231
+ val input = """ {}"""
232
+ val mapper = newBuilder.enable(DeserializationFeature .FAIL_ON_NULL_CREATOR_PROPERTIES ).build()
233
+ intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException ] {
234
+ mapper.readValue(input, classOf [MapHolder [Int , String ]])
235
+ }
236
+ }
237
+
221
238
}
You can’t perform that action at this time.
0 commit comments