kamikat / moshi-jsonapi

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

JsonApiError in minify mode #54

Closed mirmousaviii closed 7 years ago

mirmousaviii commented 7 years ago

I used JsonApiError, But the error message shows when I using minify atribute in gradle.

E/UncaughtException: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
...

Code:

JsonApiError apiError = null;
try {
    apiError = new Moshi.Builder().build().adapter(JsonApiError.class).fromJson(response.errorBody().source());
} catch (IOException e) {
    e.printStackTrace();
}
int testSize = apiError.getErrors().size();
String testDetail = apiError.getErrors().get(1).getDetail();
String testTitle = apiError.getErrors().get(1).getTitle();

Sample response:

{
    "jsonapi": {
    "version": "1.0"
},
    "errors": [
    {
        "detail": "this is test",
         "source": {
             "pointer": "/data/attributes/otp"
         }
    }
]
}
kamikat commented 7 years ago

Maybe we should keep JsonApiError from being obfuscated

-keep public class moe.banana.jsonapi2.**

And I'll suggest upgrading to 3.x for better performance and cleaner interface 🍻

mirmousaviii commented 7 years ago

It's solved with this keep. OK, I will update soon. Thanks.