Skip to content

Commit

Permalink
Merge branch '2.18' into fix-4388
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jul 11, 2024
2 parents 0c5671d + 4195142 commit 9a04fa6
Show file tree
Hide file tree
Showing 17 changed files with 801 additions and 169 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
uses: github/codeql-action/init@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
uses: github/codeql-action/autobuild@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
2 changes: 1 addition & 1 deletion .github/workflows/dep_build_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up JDK
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dep_build_v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: master
- name: Set up JDK
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up JDK
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
run: ./mvnw -B -q -ff -ntp test
- name: Publish code coverage
if: ${{ github.event_name != 'pull_request' && matrix.release_build }}
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./target/site/jacoco/jacoco.xml
Expand Down
10 changes: 10 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,11 @@ Peter Levart (plevart@github)
a Converter that may return null for a non-null input
(2.17.2)

Susan Witts (susanw1@github)
* Reported #4607: `MismatchedInput`: No Object Id found for an instance of X to
assign to property '@id'
(2.17.2)

Ulf Dreyer (u3r@github)
* Reported #4085: `@JsonView` does not work on class-level for records
(2.18.0)
Expand Down Expand Up @@ -1812,3 +1817,8 @@ Alexandre Jacob (ajacob@github)
* Reported #4545: Unexpected deserialization behavior with `@JsonCreator`,
`@JsonProperty` and javac `-parameters`
(2.18.0)
Eduard Gomoliako (Gems@github)
* Reported #4602: Possible wrong use of _arrayDelegateDeserializer in
BeanDeserializerBase::deserializeFromObjectUsingNonDefault()
(2.18.0)
13 changes: 12 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ Project: jackson-databind
#4570: Deprecate `ObjectMapper.canDeserialize()`/`ObjectMapper.canSerialize()`
#4580: Add `MapperFeature.SORT_CREATOR_PROPERTIES_BY_DECLARATION_ORDER` to use
Creator properties' declaration order for sorting
#4584: Provide extension point for detecting "primary" Constructor for Kotlin
(and similar) data classes
#4602: Possible wrong use of _arrayDelegateDeserializer in
BeanDeserializerBase::deserializeFromObjectUsingNonDefault()
(reported by Eduard G)

2.17.2 (not yet released)
2.17.2 (05-Jul-2024)

#4561: Issues using jackson-databind 2.17.1 with Reactor
(reported by @wdallastella)
Expand All @@ -63,6 +68,12 @@ Project: jackson-databind
(reported by @dmelisso)
#4595: No way to explicitly disable wrapping in custom annotation processor
(reported by @SimonCockx)
#4607: `MismatchedInput`: No Object Id found for an instance of X to
assign to property '@id'
(reported by Susan W)
#4610: `DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS` does not work when
used with Polymorphic type handling
(fix by Joo-Hyuk K)

2.17.1 (04-May-2024)

Expand Down
179 changes: 108 additions & 71 deletions src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,

/*
/**********************************************************
/* Deserialization: class annotations
/* Deserialization: value instantiation, Creators
/**********************************************************
*/

Expand Down Expand Up @@ -1365,76 +1365,6 @@ public JsonPOJOBuilder.Value findPOJOBuilderConfig(AnnotatedClass ac) {
return null;
}

/*
/**********************************************************
/* Deserialization: property annotations
/**********************************************************
*/

/**
* Method for checking whether given property accessors (method,
* field) has an annotation that suggests property name to use
* for deserialization (reading JSON into POJOs).
* Should return null if no annotation
* is found; otherwise a non-null name (possibly
* {@link PropertyName#USE_DEFAULT}, which means "use default heuristics").
*
* @param ann Annotated entity to check
*
* @return Name to use if found; {@code null} if not.
*
* @since 2.1
*/
public PropertyName findNameForDeserialization(Annotated ann) {
return null;
}

/**
* Method for checking whether given method has an annotation
* that suggests that the method is to serve as "any setter";
* method to be used for setting values of any properties for
* which no dedicated setter method is found.
*
* @param ann Annotated entity to check
*
* @return {@code Boolean.TRUE} or {@code Boolean.FALSE} if explicit
* "any setter" marker found; {@code null} otherwise.
*
* @since 2.9
*/
public Boolean hasAnySetter(Annotated ann) {
return null;
}

/**
* Method for finding possible settings for property, given annotations
* on an accessor.
*
* @param ann Annotated entity to check
*
* @return Setter info value found, if any;
* {@code JsonSetter.Value.empty()} if none (should not return {@code null})
*
* @since 2.9
*/
public JsonSetter.Value findSetterInfo(Annotated ann) {
return JsonSetter.Value.empty();
}

/**
* Method for finding merge settings for property, if any.
*
* @param ann Annotated entity to check
*
* @return {@code Boolean.TRUE} or {@code Boolean.FALSE} if explicit
* merge enable/disable found; {@code null} otherwise.
*
* @since 2.9
*/
public Boolean findMergeInfo(Annotated ann) {
return null;
}

/**
* Method called to check whether potential Creator (constructor or static factory
* method) has explicit annotation to indicate it as actual Creator; and if so,
Expand Down Expand Up @@ -1467,6 +1397,43 @@ public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated
return null;
}

/**
* Method called to check if introspector can find a Creator it considers
* the "Default Creator": Creator to use as the primary, when no Creator has
* explicit annotation ({@link #findCreatorAnnotation} returns {@code null}).
* Examples of default creators include the canonical constructor defined by
* Java Records; "Data" classes by frameworks
* like Lombok and JVM languages like Kotlin and Scala (case classes) also have
* similar concepts.
* If introspector can determine that one of given {@link PotentialCreator}s should
* be considered the default, it should return it; if not, should return {@code null}.
* Note that core databind functionality may call this method even in the presence of
* explicitly annotated creators; and may or may not use Creator returned depending
* on other criteria.
*<p>
* NOTE: when returning chosen Creator, it may be necessary to mark its "mode"
* with {@link PotentialCreator#overrideMode} (especially for "delegating" creators).
*<p>
* NOTE: method is NOT called for Java Record types; selection of the canonical constructor
* as the Primary creator is handled directly by {@link POJOPropertiesCollector}
*
* @param config Configuration settings in effect (for deserialization)
* @param valueClass Class being instantiated; defines Creators passed
* @param declaredConstructors Constructors value class declares
* @param declaredFactories Factory methods value class declares
*
* @return Default Creator to possibly use for {@code valueClass}, if one can be
* determined; {@code null} if not.
*
* @since 2.18
*/
public PotentialCreator findDefaultCreator(MapperConfig<?> config,
AnnotatedClass valueClass,
List<PotentialCreator> declaredConstructors,
List<PotentialCreator> declaredFactories) {
return null;
}

/**
* Method for checking whether given annotated item (method, constructor)
* has an annotation
Expand Down Expand Up @@ -1504,6 +1471,76 @@ public JsonCreator.Mode findCreatorBinding(Annotated ann) {
return null;
}

/*
/**********************************************************
/* Deserialization: other property annotations
/**********************************************************
*/

/**
* Method for checking whether given property accessors (method,
* field) has an annotation that suggests property name to use
* for deserialization (reading JSON into POJOs).
* Should return null if no annotation
* is found; otherwise a non-null name (possibly
* {@link PropertyName#USE_DEFAULT}, which means "use default heuristics").
*
* @param ann Annotated entity to check
*
* @return Name to use if found; {@code null} if not.
*
* @since 2.1
*/
public PropertyName findNameForDeserialization(Annotated ann) {
return null;
}

/**
* Method for checking whether given method has an annotation
* that suggests that the method is to serve as "any setter";
* method to be used for setting values of any properties for
* which no dedicated setter method is found.
*
* @param ann Annotated entity to check
*
* @return {@code Boolean.TRUE} or {@code Boolean.FALSE} if explicit
* "any setter" marker found; {@code null} otherwise.
*
* @since 2.9
*/
public Boolean hasAnySetter(Annotated ann) {
return null;
}

/**
* Method for finding possible settings for property, given annotations
* on an accessor.
*
* @param ann Annotated entity to check
*
* @return Setter info value found, if any;
* {@code JsonSetter.Value.empty()} if none (should not return {@code null})
*
* @since 2.9
*/
public JsonSetter.Value findSetterInfo(Annotated ann) {
return JsonSetter.Value.empty();
}

/**
* Method for finding merge settings for property, if any.
*
* @param ann Annotated entity to check
*
* @return {@code Boolean.TRUE} or {@code Boolean.FALSE} if explicit
* merge enable/disable found; {@code null} otherwise.
*
* @since 2.9
*/
public Boolean findMergeInfo(Annotated ann) {
return null;
}

/**
* @param am Annotated method to check
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,22 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom deserializers
p.assignCurrentValue(bean);

// First: do we have native Object Ids (like YAML)?
if (p.canReadObjectId()) {
Object id = p.getObjectId();
if (id != null) {
_handleTypedObjectId(p, ctxt, bean, id);
}
}
// [databind#3838]: since 2.16 Uniform handling of missing objectId
// only for the specific "empty JSON Object" case
if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) {
ctxt.reportUnresolvedObjectId(_objectIdReader, bean);
// only for the specific "empty JSON Object" case (and only for non-Native
// Object Ids, see [databind#4607]
else if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) {
// [databind#4610]: check if we are to skip failure
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)) {
ctxt.reportUnresolvedObjectId(_objectIdReader, bean);
}
}
if (_injectables != null) {
injectValues(ctxt, bean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,9 @@ protected Object deserializeFromObjectId(JsonParser p, DeserializationContext ct
protected Object deserializeFromObjectUsingNonDefault(JsonParser p,
DeserializationContext ctxt) throws IOException
{
final JsonDeserializer<Object> delegateDeser = _delegateDeserializer();
// 02-Jul-2024, tatu: [databind#4602] Need to tweak regular and "array" delegating
// Creator handling
final JsonDeserializer<Object> delegateDeser = _delegateDeserializer(p);
if (delegateDeser != null) {
final Object bean = _valueInstantiator.createUsingDelegate(ctxt,
delegateDeser.deserialize(p, ctxt));
Expand All @@ -1505,7 +1507,7 @@ protected Object deserializeFromObjectUsingNonDefault(JsonParser p,
// 01-May-2022, tatu: [databind#3417] special handling for (Graal) native images
if (NativeImageUtil.needsReflectionConfiguration(raw)) {
return ctxt.handleMissingInstantiator(raw, null, p,
"cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized");
"cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized");
}
return ctxt.handleMissingInstantiator(raw, getValueInstantiator(), p,
"cannot deserialize from Object value (no delegate- or property-based Creator)");
Expand Down Expand Up @@ -1710,6 +1712,30 @@ protected final JsonDeserializer<Object> _delegateDeserializer() {
return deser;
}

/**
* Alternate to {@link #_delegateDeserializer()} which will only consider
* {@code _arrayDelegateDeserializer} if given {@link JsonParser} points to
* {@link JsonToken#START_ARRAY} token.
*
* @since 2.18
*/
protected final JsonDeserializer<Object> _delegateDeserializer(JsonParser p) {
if (_delegateDeserializer == null) {
// Note! Will not call `JsonParser.isExpectedArrayToken()` as that could
// "transform" `JsonToken.START_OBJECT` into `JsonToken.START_ARRAY` and
// here there is no strong expectation of Array value
if (_arrayDelegateDeserializer != null) {
// Alas, need bit elaborate logic: either JSON Array, OR no
// Properties-based Creator
if (p.hasToken(JsonToken.START_ARRAY)
|| (_propertyBasedCreator == null)) {
return _arrayDelegateDeserializer;
}
}
}
return _delegateDeserializer;
}

/*
/**********************************************************
/* Overridable helper methods
Expand Down
Loading

0 comments on commit 9a04fa6

Please sign in to comment.