Skip to content

Commit 84ff962

Browse files
authored
Final fixes (#5394)
1 parent f6f5b92 commit 84ff962

File tree

8 files changed

+60
-10
lines changed

8 files changed

+60
-10
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
437437
p.skipChildren();
438438
continue;
439439
}
440+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
441+
if (creatorProp.isInjectionOnly()) {
442+
// Skip the input value, will be injected later in PropertyValueBuffer
443+
p.skipChildren();
444+
continue;
445+
}
440446
value = _deserializeWithErrorWrapping(p, ctxt, creatorProp);
441447
// Last creator property to set?
442448
if (buffer.assignParameter(creatorProp, value)) {
@@ -886,6 +892,13 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
886892
continue;
887893
}
888894
if (creatorProp != null) {
895+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
896+
if (creatorProp.isInjectionOnly()) {
897+
// Skip the input value, will be injected later in PropertyValueBuffer
898+
p.skipChildren();
899+
continue;
900+
}
901+
889902
// Last creator property to set?
890903
if (buffer.assignParameter(creatorProp,
891904
_deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
@@ -1094,6 +1107,13 @@ protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p,
10941107
continue;
10951108
}
10961109
if (creatorProp != null) {
1110+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
1111+
if (creatorProp.isInjectionOnly()) {
1112+
// Skip the input value, will be injected later in PropertyValueBuffer
1113+
p.skipChildren();
1114+
continue;
1115+
}
1116+
10971117
// first: let's check to see if this might be part of value with external type id:
10981118
// 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null,
10991119
// since it is not the bean

src/main/java/com/fasterxml/jackson/databind/deser/BuilderBasedDeserializer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p,
384384
p.skipChildren();
385385
continue;
386386
}
387+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
388+
if (creatorProp.isInjectionOnly()) {
389+
// Skip the input value, will be injected later in PropertyValueBuffer
390+
p.skipChildren();
391+
continue;
392+
}
387393
// Last creator property to set?
388394
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
389395
p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
@@ -667,6 +673,13 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
667673
continue;
668674
}
669675
if (creatorProp != null) {
676+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
677+
if (creatorProp.isInjectionOnly()) {
678+
// Skip the input value, will be injected later in PropertyValueBuffer
679+
p.skipChildren();
680+
continue;
681+
}
682+
670683
// Last creator property to set?
671684
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
672685
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT

src/main/java/com/fasterxml/jackson/databind/deser/CreatorProperty.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ public class CreatorProperty
3939
protected final AnnotatedParameter _annotated;
4040

4141
/**
42-
* Id of value to inject, if value injection should be used for this parameter
42+
* Injection settings, if value injection should be used for this parameter
4343
* (in addition to, or instead of, regular deserialization).
44+
*<p>
45+
* NOTE: badly named, should be more like "_injectionDefinition" but
46+
* renaming would be a breaking (internal) change.
4447
*
4548
* @since 2.11
4649
*/

src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanAsArrayBuilderDeserializer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p,
304304
continue;
305305
}
306306
if (creatorProp != null) {
307+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
308+
if (creatorProp.isInjectionOnly()) {
309+
// Skip the input value, will be injected later in PropertyValueBuffer
310+
p.skipChildren();
311+
continue;
312+
}
313+
307314
// Last creator property to set?
308315
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
309316
try {

src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanAsArrayDeserializer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p, final
320320
continue;
321321
}
322322
if (creatorProp != null) {
323+
// [databind#1381]: if useInput=FALSE, skip deserialization from input
324+
if (creatorProp.isInjectionOnly()) {
325+
// Skip the input value, will be injected later in PropertyValueBuffer
326+
p.skipChildren();
327+
continue;
328+
}
329+
323330
// Last creator property to set?
324331
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
325332
try {

src/test/java/com/fasterxml/jackson/databind/deser/inject/JacksonInject1381DeserializationFeatureDisabledTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ void test2() throws Exception {
137137
}
138138

139139
@Test
140-
@DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable NO, useInput DEFAULT|FALSE => exception")
140+
@DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable NO, useInput DEFAULT|FALSE => [varied]")
141141
void test3() throws Exception {
142142
assertEquals("input", plainMapper.readValue(input, InputDefault.class).getField());
143143
assertEquals("input", plainMapper.readValue(input, InputDefaultConstructor.class).getField());
144-
assertEquals("input", plainMapper.readValue(input, InputFalse.class).getField());
145-
assertEquals("input", plainMapper.readValue(input, InputFalseConstructor.class).getField());
144+
assertNull(plainMapper.readValue(input, InputFalse.class).getField());
145+
assertNull(plainMapper.readValue(input, InputFalseConstructor.class).getField());
146146
}
147147

148148
@Test

src/test/java/com/fasterxml/jackson/databind/deser/inject/JacksonInject1381WithOptionalDeserializationFeatureDisabledTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ void test2() throws Exception {
142142
}
143143

144144
@Test
145-
@DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, optional YES, input YES, injectable NO, useInput DEFAULT|TRUE|FALSE => input")
145+
@DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, optional YES, input YES, injectable NO, useInput DEFAULT|TRUE|FALSE => [varied]")
146146
void test3() throws Exception {
147147
assertEquals("input", plainMapper.readValue(input, InputDefault.class).getField());
148148
assertEquals("input", plainMapper.readValue(input, InputDefaultConstructor.class).getField());
149-
assertEquals("input", plainMapper.readValue(input, InputFalse.class).getField());
150-
assertEquals("input", plainMapper.readValue(input, InputFalseConstructor.class).getField());
149+
assertNull(plainMapper.readValue(input, InputFalse.class).getField());
150+
assertNull(plainMapper.readValue(input, InputFalseConstructor.class).getField());
151151
assertEquals("input", plainMapper.readValue(input, InputTrue.class).getField());
152152
assertEquals("input", plainMapper.readValue(input, InputTrueConstructor.class).getField());
153153
}

src/test/java/com/fasterxml/jackson/databind/deser/inject/JacksonInject1381WithOptionalTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ void test2() throws Exception {
139139
}
140140

141141
@Test
142-
@DisplayName("optional YES, input YES, injectable NO, useInput DEFAULT|TRUE|FALSE => input")
142+
@DisplayName("optional YES, input YES, injectable NO, useInput DEFAULT|TRUE|FALSE => [varied]")
143143
void test3() throws Exception {
144144
assertEquals("input", plainMapper.readValue(input, InputDefault.class).getField());
145145
assertEquals("input", plainMapper.readValue(input, InputDefaultConstructor.class).getField());
146-
assertEquals("input", plainMapper.readValue(input, InputFalse.class).getField());
147-
assertEquals("input", plainMapper.readValue(input, InputFalseConstructor.class).getField());
146+
assertNull(plainMapper.readValue(input, InputFalse.class).getField());
147+
assertNull(plainMapper.readValue(input, InputFalseConstructor.class).getField());
148148
assertEquals("input", plainMapper.readValue(input, InputTrue.class).getField());
149149
assertEquals("input", plainMapper.readValue(input, InputTrueConstructor.class).getField());
150150
}

0 commit comments

Comments
 (0)