Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor is not recognized when a record uses both arrays and generic types #251

Closed
HelloOO7 opened this issue Sep 3, 2024 · 1 comment · Fixed by #252
Closed

Constructor is not recognized when a record uses both arrays and generic types #251

HelloOO7 opened this issue Sep 3, 2024 · 1 comment · Fixed by #252
Labels
2.18 android-records Issue related to Android Records module
Milestone

Comments

@HelloOO7
Copy link
Contributor

HelloOO7 commented Sep 3, 2024

Given a record that contains both an array member and a generic type member, such as:

public record Test(
    int[] numberArray,
    Map<Integer, Integer> numberMap) {
}

this structure will fail to deserialize on Android with no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator.

I've researched this further and it seems like this is, in fact, an Android bug, and not a Jackson bug. If generic types are used (anywhere) in a class declaration, then Android's libcore parses the type descriptors in a way that arrays are always instances of GenericArrayType and other types are always ParameterizedTypes. I'm almost certain this must be breaking some Java specification, and even if not, it is incredibly ugly. (for comedic effect, see here regarding how this behavior is worked around so that methods like "getGenericComponentType" work properly) (and for additional comedic effect, the average pay at Google is about $120K a year)

Since I reckon there's no point in trying to make Google fix this mess themselves (it has apparently been causing issues at least as early as 2018), I would rather propose to work around it in Jackson since it does break deserialization of quite a lot of realistic scenarios. I have made a fix for myself already and I can PR it if wanted, I would just need to rebase it to whatever point Jackson is currently at (it is currently based on where it was as of #248).

@cowtowncoder cowtowncoder added 2.18 android-records Issue related to Android Records module labels Sep 3, 2024
@cowtowncoder
Copy link
Member

First of all: thank you for taking time to investigate this thoroughly & document the problem.

Patch would be very welcome, against 2.18 branch -- 2.18.0-rc1 was just released but we could get fix in 2.18.0 final likely.

@cowtowncoder cowtowncoder changed the title android-record: Constructor is not recognized when a record uses both arrays and generic types Constructor is not recognized when a record uses both arrays and generic types Sep 4, 2024
@cowtowncoder cowtowncoder added this to the 2.18.0 milestone Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 android-records Issue related to Android Records module
Projects
None yet
2 participants