You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a Resource model class with Kotlin some features are not supported, like custom-named fields with @Json (see square/moshi#315). However, moshi introduced moshi-kotlin and moshi-kotlin-codegen to fix that. A current limitation is that the superclass needs to be a Kotlin class as well, which is not the case for Resource.
Even without the superclass problem I am unsure whether these libraries work together with this one. The reflection approach needs a separate adapter factory:
val moshi =Moshi.Builder()
// ... add your own JsonAdapters and factories ...
.add(KotlinJsonAdapterFactory())
.build()
Looks like this would require to adjust the ResourceAdapterFactory.
The codegen approach generates adapters at compile time. Maybe this approach could be used together with ResourceAdapterFactory? It is also the recommended one since its footprint is much smaller.
As a workaround for this specific feature (@Json annotation) @field:Json can be used. At least it worked for me. But it is not recommended or tested.
The text was updated successfully, but these errors were encountered:
Since this issue is still open I gonna comment here. I have the same issue right now with Moshi 1.8 (with Moshi-Kotlin), @Json is ignored on release build but works in Debug. Now I have changed @Json to @field:Json everywhere but now it doesn't work in my tests anymore when I run them in debug mode. Any solutions for this?
When creating a
Resource
model class with Kotlin some features are not supported, like custom-named fields with@Json
(see square/moshi#315). However, moshi introduced moshi-kotlin and moshi-kotlin-codegen to fix that. A current limitation is that the superclass needs to be a Kotlin class as well, which is not the case forResource
.Even without the superclass problem I am unsure whether these libraries work together with this one. The reflection approach needs a separate adapter factory:
Looks like this would require to adjust the
ResourceAdapterFactory
.The codegen approach generates adapters at compile time. Maybe this approach could be used together with
ResourceAdapterFactory
? It is also the recommended one since its footprint is much smaller.As a workaround for this specific feature (
@Json
annotation)@field:Json
can be used. At least it worked for me. But it is not recommended or tested.The text was updated successfully, but these errors were encountered: