kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 35 forks source link

Problem with embedded field with name 'type' #87

Closed mkonkel closed 5 years ago

mkonkel commented 5 years ago

Hi!

I am unable to parse any response that contains a custom field named "type'"

example:

@JsonApi(type="person")
public class PersonRequest extends Resource {
  @Json(name="name") public String firstName;
  /.../
  @Json(name="type") public String personType; //can be [KID, ADULT]
}

personType is allways 'null' any solution for that?

es0329 commented 5 years ago

The spec states fields shouldn't be named id or type. If possible, you might consider different variables names.

mkonkel commented 5 years ago

That's true - but unfortunately, I can't change the API.

I've switched from Kotlin data classes to Java models. And I wrote a custom converter on 'CharSequencefor a field namedtype` -it's a poor workaround but it works.