Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 4, 2024
2 parents e4f162a + 7ae022a commit 290f52a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dep_build_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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 @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package tools.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.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.lang.reflect.*;
import java.util.*;

import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -136,7 +131,7 @@ public PotentialCreator findDefaultCreator(MapperConfig<?> config,
AnnotatedConstructor constructor = (AnnotatedConstructor) creator.creator();
Parameter[] parameters = constructor.getAnnotated().getParameters();
Map<String, Type> 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) {
Expand Down Expand Up @@ -168,4 +163,31 @@ static boolean isDesugaredRecordClass(Class<?> raw) {
static Stream<Field> 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) {
Type componentType = fixAndroidGenericType(((GenericArrayType) type).getGenericComponentType());
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;
if (parameterizedType.getOwnerType() == null) {
Type rawType = parameterizedType.getRawType();
if (rawType instanceof Class<?>) {
Class<?> rawComponentClass = (Class<?>) rawType;
if (rawComponentClass.getTypeParameters().length == 0) {
return rawComponentClass;
}
}
}
}
return type;
}
}
7 changes: 5 additions & 2 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,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)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 290f52a

Please sign in to comment.