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.