From d9fae8e7ad7d9f1988a4a928d4ada9b1b4ab6a96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:48:47 +0000 Subject: [PATCH 1/4] Bump actions/setup-java from 4.2.1 to 4.2.2 in the github-actions group Bumps the github-actions group with 1 update: [actions/setup-java](https://github.com/actions/setup-java). Updates `actions/setup-java` from 4.2.1 to 4.2.2 - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/99b8673ff64fbf99d8d325f52d9a5bdedb8483e9...6a0805fcefea3d4657a47ac4c165951e33482018) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions ... Signed-off-by: dependabot[bot] --- .github/workflows/dep_build_v2.yml | 2 +- .github/workflows/dep_build_v3.yml | 2 +- .github/workflows/main.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dep_build_v2.yml b/.github/workflows/dep_build_v2.yml index 03bd636e..2f27651a 100644 --- a/.github/workflows/dep_build_v2.yml +++ b/.github/workflows/dep_build_v2.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Set up JDK - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 + uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} diff --git a/.github/workflows/dep_build_v3.yml b/.github/workflows/dep_build_v3.yml index ee4b8e34..207b38f0 100644 --- a/.github/workflows/dep_build_v3.yml +++ b/.github/workflows/dep_build_v3.yml @@ -23,7 +23,7 @@ jobs: with: ref: master - name: Set up JDK - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 + uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e8ba442..a57423dc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,7 @@ jobs: steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Set up JDK - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 + uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} From 032b52e668f74b7d5e3664893a7d606d8699dc2f Mon Sep 17 00:00:00 2001 From: HelloOO7 Date: Tue, 3 Sep 2024 19:27:07 +0200 Subject: [PATCH 2/4] android-record: Adapt generic types returned by Android reflection to follow Java behavior. --- .../androidrecord/AndroidRecordModule.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java b/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java index efea669d..92ee6dba 100644 --- a/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java +++ b/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java @@ -1,9 +1,6 @@ package com.fasterxml.jackson.module.androidrecord; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.lang.reflect.Parameter; -import java.lang.reflect.Type; +import java.lang.reflect.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -119,7 +116,7 @@ public PotentialCreator findDefaultCreator(MapperConfig config, AnnotatedConstructor constructor = (AnnotatedConstructor) creator.creator(); Parameter[] parameters = constructor.getAnnotated().getParameters(); Map parameterTypes = Arrays.stream(parameters) - .collect(Collectors.toMap(Parameter::getName, Parameter::getParameterizedType)); + .collect(Collectors.toMap(Parameter::getName, parameter -> fixAndroidGenericType(parameter.getParameterizedType()))); if (parameterTypes.equals(components)) { if (foundCreator != null) { @@ -150,4 +147,30 @@ static boolean isDesugaredRecordClass(Class raw) { static Stream getDesugaredRecordComponents(Class raw) { return Arrays.stream(raw.getDeclaredFields()).filter(field -> !Modifier.isStatic(field.getModifiers())); } + + static Class arrayTypeCompat(Class componentType) { + return Array.newInstance(componentType, 0).getClass(); + } + + static Type fixAndroidGenericType(Type type) { + if (type instanceof GenericArrayType) { + //recurse into component type + Type componentType = fixAndroidGenericType(((GenericArrayType) type).getGenericComponentType()); + if (componentType instanceof Class) { //if it isn't generic, return the raw array type + return arrayTypeCompat((Class) componentType); + } + } + else if (type instanceof ParameterizedType) { + //if the parameterized type is not actually parameterized, deduce the raw type + ParameterizedType parameterizedType = (ParameterizedType) type; + Type rawType = parameterizedType.getRawType(); + if (rawType instanceof Class) { + Class rawComponentClass = (Class) rawType; + if (rawComponentClass.getTypeParameters().length == 0) { + return rawComponentClass; + } + } + } + return type; + } } From fb007fd75c20f88c7510d831826dff14811eb72a Mon Sep 17 00:00:00 2001 From: HelloOO7 Date: Tue, 3 Sep 2024 19:30:04 +0200 Subject: [PATCH 3/4] android-record: Adapt generic types returned by Android reflection to follow Java behavior. --- .../module/androidrecord/AndroidRecordModule.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java b/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java index 92ee6dba..4ac5c872 100644 --- a/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java +++ b/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java @@ -154,20 +154,21 @@ static Class arrayTypeCompat(Class componentType) { static Type fixAndroidGenericType(Type type) { if (type instanceof GenericArrayType) { - //recurse into component type Type componentType = fixAndroidGenericType(((GenericArrayType) type).getGenericComponentType()); - if (componentType instanceof Class) { //if it isn't generic, return the raw array type + if (componentType instanceof Class) { return arrayTypeCompat((Class) componentType); } } else if (type instanceof ParameterizedType) { //if the parameterized type is not actually parameterized, deduce the raw type ParameterizedType parameterizedType = (ParameterizedType) type; - Type rawType = parameterizedType.getRawType(); - if (rawType instanceof Class) { - Class rawComponentClass = (Class) rawType; - if (rawComponentClass.getTypeParameters().length == 0) { - return rawComponentClass; + if (parameterizedType.getOwnerType() == null) { + Type rawType = parameterizedType.getRawType(); + if (rawType instanceof Class) { + Class rawComponentClass = (Class) rawType; + if (rawComponentClass.getTypeParameters().length == 0) { + return rawComponentClass; + } } } } From 7ae022a60ca2b6983ce287ea5e3187dfcdf75136 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 3 Sep 2024 17:31:51 -0700 Subject: [PATCH 4/4] Update release notes --- release-notes/CREDITS-2.x | 7 +++++-- release-notes/VERSION-2.x | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 6d7dba2e..4c572295 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -155,5 +155,8 @@ Jack Dunning (@JDUNNIN) @HelloOO7 * Contributed #248: (android-record) jClass annotations and polymorphic types are ignored - when deserializing Android Record fields - (2.18.0) + when deserializing Android Record fields* + (2.18.0) +* Contributed #251: Constructor is not recognized when a record uses both arrays + and generic types + (2.18.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 36f1fb76..774af620 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -31,6 +31,9 @@ Active maintainers: #248: (android-record) jClass annotations and polymorphic types are ignored when deserializing Android Record fields (contributed by @HelloOO7) +#251: (android-record) Constructor is not recognized when a record uses + both arrays and generic types + (contributed by @HelloOO7) 2.17.2 (05-Jul-2024) 2.17.1 (04-May-2024)