Skip to content

fix(serialization): use full JavaType in decodeFromJSONElement to preserve generics#2116

Merged
Andrey Bragin (EugeneTheDev) merged 3 commits into
JetBrains:developfrom
monrax:fix/serialization-jackson-javatype
Jun 8, 2026
Merged

fix(serialization): use full JavaType in decodeFromJSONElement to preserve generics#2116
Andrey Bragin (EugeneTheDev) merged 3 commits into
JetBrains:developfrom
monrax:fix/serialization-jackson-javatype

Conversation

@monrax

Copy link
Copy Markdown
Contributor

JacksonSerializer.decodeFromJSONElement was passing javaType.rawClass to objectMapper.treeToValue, discarding generic type parameters. This causes parameterized types (e.g. List<Person>) to deserialize elements as Map instead of the expected type.

The fix passes the full JavaType to treeToValue, consistent with how decodeFromString already works. This also removes the now-unnecessary @Suppress("UNCHECKED_CAST") and explicit as T cast.

closes #2115

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix, thank you. Can you please run ktlintFormat to fix formatting issues?

@monrax

Copy link
Copy Markdown
Contributor Author

Nice fix, thank you. Can you please run ktlintFormat to fix formatting issues?

Andrey Bragin (@EugeneTheDev) thank you for the quick reply! Done 👍

@EugeneTheDev
Andrey Bragin (EugeneTheDev) merged commit 58a8168 into JetBrains:develop Jun 8, 2026
22 checks passed
@monrax
Ramón Márquez (monrax) deleted the fix/serialization-jackson-javatype branch June 9, 2026 19:29
Kaloyan Karaivanov (karloti) pushed a commit to karloti/koog that referenced this pull request Jun 13, 2026
…serve generics (JetBrains#2116)

`JacksonSerializer.decodeFromJSONElement` was passing
`javaType.rawClass` to `objectMapper.treeToValue`, discarding generic
type parameters. This causes parameterized types (e.g. `List<Person>`)
to deserialize elements as `Map` instead of the expected type.

The fix passes the full `JavaType` to `treeToValue`, consistent with how
`decodeFromString` already works. This also removes the now-unnecessary
`@Suppress("UNCHECKED_CAST")` and explicit `as T` cast.

closes JetBrains#2115
Andrey Bragin (EugeneTheDev) pushed a commit that referenced this pull request Jun 15, 2026
…serve generics (#2116)

`JacksonSerializer.decodeFromJSONElement` was passing
`javaType.rawClass` to `objectMapper.treeToValue`, discarding generic
type parameters. This causes parameterized types (e.g. `List<Person>`)
to deserialize elements as `Map` instead of the expected type.

The fix passes the full `JavaType` to `treeToValue`, consistent with how
`decodeFromString` already works. This also removes the now-unnecessary
`@Suppress("UNCHECKED_CAST")` and explicit `as T` cast.

closes #2115

(cherry picked from commit 58a8168)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] JavaType should be used in decodeFromJSONElement instead of rawClass

2 participants