Skip to content

Commit 885cf2e

Browse files
committed
Merge branch '2.18' into 2.19
2 parents e67dec2 + 47e0736 commit 885cf2e

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,10 @@ wrongwrong (@k163377)
18491849
serializer lookup was done on the pre-converted value when _delegateSerializer was null
18501850
(2.18.1)
18511851

1852+
Bernd Ahlers (@bernd)
1853+
* Reported #4742: Deserialization with Builder, External type id, `@JsonCreator` failing
1854+
(2.18.2)
1855+
18521856
Mike Minicki (@martel)
18531857
* Reported #4788: `EnumFeature.WRITE_ENUMS_TO_LOWERCASE` overrides `@JsonProperty` values
18541858
(2.18.2)

release-notes/VERSION-2.x

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Project: jackson-databind
3838

3939
#4733: Wrong serialization of Type Ids for certain types of Enum values
4040
(reported by @nlisker)
41+
#4742: Deserialization with Builder, External type id, `@JsonCreator` failing
42+
(reported by Bernd A)
43+
#4777: `StdValueInstantiator.withArgsCreator` is now set for creators with
44+
no arguments
45+
(reported by @wrongwrong)
4146
#4783 Possibly wrong behavior of @JsonMerge
4247
(reported by @nlisker)
4348
(fix by Joo-Hyuk K)
@@ -70,7 +75,7 @@ Project: jackson-databind
7075
(fix by Joo-Hyuk K)
7176
#4749: Fixed a problem with `StdDelegatingSerializer#serializeWithType` looking up the serializer
7277
with the wrong argument
73-
(fix by wrongwrong)
78+
(fix by @wrongwrong)
7479

7580
2.18.0 (26-Sep-2024)
7681

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,16 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
250250
if (potentialCreators.hasPropertiesBased()) {
251251
PotentialCreator primaryPropsBased = potentialCreators.propertiesBased;
252252

253-
// Start by assigning the primary (and only) properties-based creator
254-
_addSelectedPropertiesBasedCreator(ctxt, beanDesc, creators,
255-
CreatorCandidate.construct(config.getAnnotationIntrospector(),
256-
primaryPropsBased.creator(), primaryPropsBased.propertyDefs()));
253+
// 12-Nov-2024, tatu: [databind#4777] We may have collected a 0-args Factory
254+
// method; and if so, may need to "pull it out" as default creator
255+
if (primaryPropsBased.paramCount() == 0) {
256+
creators.setDefaultCreator(primaryPropsBased.creator());
257+
} else {
258+
// Start by assigning the primary (and only) properties-based creator
259+
_addSelectedPropertiesBasedCreator(ctxt, beanDesc, creators,
260+
CreatorCandidate.construct(config.getAnnotationIntrospector(),
261+
primaryPropsBased.creator(), primaryPropsBased.propertyDefs()));
262+
}
257263
}
258264

259265
// Continue with explicitly annotated delegating Creators
@@ -273,9 +279,10 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
273279
// First things first: the "default constructor" (zero-arg
274280
// constructor; whether implicit or explicit) is NOT included
275281
// in list of constructors, so needs to be handled separately.
276-
AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor();
277-
if (defaultCtor != null) {
278-
if (!creators.hasDefaultCreator() || _hasCreatorAnnotation(config, defaultCtor)) {
282+
// However, we may have added one for 0-args Factory method earlier, so:
283+
if (!creators.hasDefaultCreator()) {
284+
AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor();
285+
if (defaultCtor != null) {
279286
creators.setDefaultCreator(defaultCtor);
280287
}
281288
}

src/test/java/com/fasterxml/jackson/databind/tofix/JacksonBuilderCreatorSubtype4742Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/builder/BuilderCreatorSubtype4742Test.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
package com.fasterxml.jackson.databind.tofix;
1+
package com.fasterxml.jackson.databind.deser.builder;
22

33
import java.util.List;
44

55
import org.junit.jupiter.api.Test;
66

7-
import com.fasterxml.jackson.annotation.JsonCreator;
8-
import com.fasterxml.jackson.annotation.JsonProperty;
9-
import com.fasterxml.jackson.annotation.JsonSubTypes;
10-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
7+
import com.fasterxml.jackson.annotation.*;
8+
119
import com.fasterxml.jackson.databind.ObjectMapper;
1210
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1311
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
14-
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
1512

1613
import static org.junit.jupiter.api.Assertions.assertEquals;
1714
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1815

1916
// [databind#4742] Deserialization with Builder, External type id,
20-
// @JsonCreator not yet implemented
21-
public class JacksonBuilderCreatorSubtype4742Test
17+
// @JsonCreator failing
18+
public class BuilderCreatorSubtype4742Test
2219
extends DatabindTestUtil
2320
{
2421
public static class Animals {
@@ -110,9 +107,8 @@ public String toString() {
110107

111108
private final ObjectMapper MAPPER = newJsonMapper();
112109

113-
@JacksonTestFailureExpected
114110
@Test
115-
public void testDeser() throws Exception
111+
public void testDeser4742() throws Exception
116112
{
117113
final Animals animals = MAPPER.readValue(
118114
"{\n" +
@@ -125,6 +121,5 @@ public void testDeser() throws Exception
125121
assertEquals(2, animals.animals.size());
126122
assertInstanceOf(BirdProperties.class, animals.animals.get(0).properties);
127123
assertInstanceOf(MammalProperties.class, animals.animals.get(1).properties);
128-
129124
}
130125
}

src/test/java/com/fasterxml/jackson/databind/tofix/JsonCreatorNoArgs4777Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/creators/JsonCreatorNoArgs4777Test.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.databind.tofix;
1+
package com.fasterxml.jackson.databind.deser.creators;
22

33
import org.junit.jupiter.api.Test;
44

@@ -10,29 +10,28 @@
1010
import com.fasterxml.jackson.databind.json.JsonMapper;
1111
import com.fasterxml.jackson.databind.module.SimpleModule;
1212
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
13-
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
1413

1514
import static org.junit.jupiter.api.Assertions.assertNotNull;
1615

1716
public class JsonCreatorNoArgs4777Test extends DatabindTestUtil
1817
{
19-
static class Foo {
20-
private Foo() { }
18+
static class Foo4777 {
19+
Foo4777() { }
2120

2221
@JsonCreator
23-
static Foo create() {
24-
return new Foo();
22+
static Foo4777 create() {
23+
return new Foo4777();
2524
}
2625
}
2726

28-
static class Instantiators implements ValueInstantiators {
27+
static class Instantiators4777 implements ValueInstantiators {
2928
@Override
3029
public ValueInstantiator findValueInstantiator(
3130
DeserializationConfig config,
3231
BeanDescription beanDesc,
3332
ValueInstantiator defaultInstantiator
3433
) {
35-
if (beanDesc.getBeanClass() == Foo.class) {
34+
if (beanDesc.getBeanClass() == Foo4777.class) {
3635
AnnotatedWithParams dc = defaultInstantiator.getDefaultCreator();
3736
if (!(dc instanceof AnnotatedMethod)
3837
|| !dc.getName().equals("create")) {
@@ -47,18 +46,17 @@ public ValueInstantiator findValueInstantiator(
4746
// For [databind#4777]
4847
@SuppressWarnings("serial")
4948
@Test
50-
@JacksonTestFailureExpected
5149
public void testCreatorDetection4777() throws Exception {
5250
SimpleModule sm = new SimpleModule() {
5351
@Override
5452
public void setupModule(SetupContext context) {
5553
super.setupModule(context);
56-
context.addValueInstantiators(new Instantiators());
54+
context.addValueInstantiators(new Instantiators4777());
5755
}
5856
};
5957
ObjectMapper mapper = JsonMapper.builder().addModule(sm).build();
6058

61-
Foo result = mapper.readValue("{}", Foo.class);
59+
Foo4777 result = mapper.readValue("{}", Foo4777.class);
6260
assertNotNull(result);
6361
}
6462
}

0 commit comments

Comments
 (0)