FasterXML/jackson-modules-base

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

Closed this issue · 1 comments

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

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.