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

Type field is generated twice with JsonApiAdapter and PolymorphicAdapter #107

Open
pueffl opened this issue Mar 6, 2020 · 0 comments
Open

Comments

@pueffl
Copy link

pueffl commented Mar 6, 2020

I'm trying to generate JsonApi for an application in Kotlin and have the following adapters:

val jsonApiAdapterFactory: JsonAdapter.Factory =
ResourceAdapterFactory.builder()
.add(MessageModel::class.java)
.add(MultipartModel::class.java)
.add(BodypartModel::class.java)
.add(SingleBodyModel::class.java)
.build()

val moshi = Moshi.Builder()
        .add(jsonApiAdapterFactory)
        .add(PolymorphicJsonAdapterFactory.of(Body::class.java, "type")
                .withSubtype(MultipartModel::class.java, "multipart")
                .withSubtype(SingleBodyModel::class.java, "singlebody")
                .withSubtype(MessageModel::class.java, "message"))
        .add(PolymorphicJsonAdapterFactory.of(Part::class.java, "type")
                .withSubtype(BodypartModel::class.java, "bodypart")
                .withSubtype(MessageModel::class.java, "message"))
        .add(KotlinJsonAdapterFactory())
        .build()

@jsonapi(type = "message")
MessageModel {...}
and
@jsonapi(type = "bodypart")
BodypartModel {...} are implementing interface Part:

interface Part {
var content: Body?
}

where content is overridden the following way:
@ignore override var content: Body? = null

When I serialize the models, the field 'type' is generated twice. I could change the @jsonapi(type = "...") annotation to something else, so I see 2 'type' fields with two different values, it is generated from the JsonApi-Adapter and the Polymorpic Adapter, but I need both.

Maybe I am wrong and this can be solved in some way, but as far as I can see, the type-parameter in @jsonapi(type = "bodypart") should not be obligatory, as it is sometimes wrong to generate it.

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

1 participant