Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moshi-Kotlin Support #83

Open
tobiasrohloff opened this issue Jul 30, 2018 · 1 comment
Open

Moshi-Kotlin Support #83

tobiasrohloff opened this issue Jul 30, 2018 · 1 comment

Comments

@tobiasrohloff
Copy link

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.

@Fintasys
Copy link

Fintasys commented Sep 26, 2019

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?

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

No branches or pull requests

2 participants