79625089

Date: 2025-05-16 11:43:25
Score: 1
Natty:
Report link

The problem was that Gson is a Java library and all the types it uses are Java primitives, not Kotlin (e.g. Kotlin's Int = Java's java.lang.Integer). So it was necessary to register adapters specifically for the Java equivalents of Kotlin classes:

Instead of

.registerTypeHierarchyAdapter(Int::class.java, StrictIntDeserializer())

we need

.registerTypeHierarchyAdapter(java.lang.Integer::class.java, StrictIntDeserializer())

Otherwise Gson simply never accesses this adapter.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: likespro