kamikat / moshi-jsonapi

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

Getting null pointer exception on java.lang.String moe.banana.jsonapi2.JsonApi.type() #37

Closed deshmukhrohit11 closed 7 years ago

deshmukhrohit11 commented 7 years ago

I have Contact class with type="contacts" @JsonApi(type = "contacts") public class Contact extends Resource implements Serializable { }

But now I am creating an object of class which is sub-class of Contact. But, I am getting following error,

12-01 13:54:55.641 27318-27318/vocera.uc E/CoreApplication: Uncaught Exception java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String moe.banana.jsonapi2.JsonApi.type()' on a null object reference at moe.banana.jsonapi2.Resource.typeNameOf(Resource.java:426) at moe.banana.jsonapi2.Resource.(Resource.java:155) At Vocera. Ac. core. entity_model. Contact.(Contact.java:14)

I am doing something wrong here? Do I need to add same @JsonApi(type = "contacts") to sub-class also?

kamikat commented 7 years ago

A @JsonApi annotation is not inheritable. When you have multiple instance of the same type, the annotation should be declared on each of the class. But be cautious this may not be the best practice of JSON API specification.