Shubham AgaRwal
Shubham AgaRwal

Reputation: 4823

multiple JSON fields named exception in “RELEASE” build mode only

This is weird but serialization is done perfectly fine in DEBUG build mode as well as in all of the API responses except one. But in release mode, it's throwing illegal argument exception.

Here is the complete log for this exception:

FATAL EXCEPTION: main Process: com.example.sampleapp, PID: 30480 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleapp/com.example.sampleapp.activity.ManageStoreActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.example.sampleapp.model.seller.SellerStoreFormData
  for method ApiInterface.getSellerInfoData
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)


 Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.example.sampleapp.model.seller.SellerStoreFormData
  for method ApiInterface.getSellerInfoData
  at retrofit2.ServiceMethod$Builder.methodError(Unknown Source)
  at retrofit2.ServiceMethod$Builder.createResponseConverter(Unknown Source)
  at retrofit2.ServiceMethod$Builder.build(Unknown Source)
  at retrofit2.Retrofit.loadServiceMethod(Unknown Source)
  at retrofit2.Retrofit$1.invoke(Unknown Source)
  at java.lang.reflect.Proxy.invoke(Proxy.java:393)
  at $Proxy0.getSellerInfoData(Unknown Source)
  at com.example.sampleapp.connection.a.i(Unknown Source)
  at com.example.sampleapp.activity.ManageStoreActivity.onStart(Unknown Source)
  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
  at android.app.Activity.performStart(Activity.java:6253)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
    ... 9 more


 Caused by: java.lang.IllegalArgumentException: class com.example.sampleapp.model.seller.SellerStoreFormData declares multiple JSON fields named f
  at com.google.a.b.a.i.a(Unknown Source)
  at com.google.a.b.a.i.a(Unknown Source)
  at com.google.a.e.a(Unknown Source)
  at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(Unknown Source)
  at retrofit2.Retrofit.nextResponseBodyConverter(Unknown Source)
  at retrofit2.Retrofit.responseBodyConverter(Unknown Source)
    ... 20 more

What I have tried so far ?

  1. I have tried and looked for multiple JSON fields in same and parent class but didn't find any.
  2. Checked that the @SerializedName is different for each field.

I also have proguard enabled in release mode.

It was working fine earlier (without enabling proguard) and I was not getting any compile time error.

Upvotes: 0

Views: 875

Answers (1)

Idan
Idan

Reputation: 2879

If debug mode is working and release is the problem most chances is that's a proguard issue. Try excluding SellerStoreFormData from obfuscation.

Also, check if you have proguard Gson configuration in place and if not add it.

Upvotes: 4

Related Questions