Skip to content

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

@HelloOO7

Description

@HelloOO7

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18android-recordsIssue related to Android Records module

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions