You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue was discussed here and it seems to be closed without a solution,
@field:json works only when pro-guard is enabled and crashes in pro-guard disabled build with the exception, com.squareup.moshi.JsonDataException: Required value 'modelName'
// Works when Proguard ENABLED
@Keep
data classMoshiModel(
@field:Json(name = "model_name") valmodelName:String,
)
@Json works only when pro-guard is disabled and produces null value for modelName in pro-guard enabled build,
// Works when Proguard DISABLED
data classMoshiModel(
@Json(name ="model_name") valmodelName:String,
)
When debugged, found out that the only difference in the class KotlinJsonAdapterFactory between pro-guard enabled and disabled build is that in the obfuscated build, the condition if (!rawType.isAnnotationPresent(KOTLIN_METADATA)) return null is true so the Kotlin json adapter wasn't created and the regular moshi adapters are used which seem to be picking the @field:json annotation
Works in the version 1.4.0. We are optimizing our network parsing layer for speed and wanted to try out the latest moshi version.
Any one facing this problem still ?
UPDATE:
Issue is partly resolved after I set the kotlin-reflect and kotlin sdk version to same number, 1.8.21. Previously it was 1.9 and 1.8.21 respectively. Now KotlinJsonAdapterFactory respects only @Json or @param:Json for both obfuscated and non-obfuscated build. That is, it looks for the @Json annotation only in the constructor parameter and not at the field declaration. Now I will have to change all of the existing @field:Json to either @Json or @param:Json
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This issue was discussed here and it seems to be closed without a solution,
@field:json
works only when pro-guard is enabled and crashes in pro-guard disabled build with the exception,com.squareup.moshi.JsonDataException: Required value 'modelName'
// Works when Proguard ENABLED
@Json
works only when pro-guard is disabled and produces null value formodelName
in pro-guard enabled build,// Works when Proguard DISABLED
When debugged, found out that the only difference in the class KotlinJsonAdapterFactory between pro-guard enabled and disabled build is that in the obfuscated build, the condition
if (!rawType.isAnnotationPresent(KOTLIN_METADATA)) return null
is true so the Kotlin json adapter wasn't created and the regular moshi adapters are used which seem to be picking the @field:json annotationWorks in the version
1.4.0
. We are optimizing our network parsing layer for speed and wanted to try out the latest moshi version.Any one facing this problem still ?
UPDATE:
Issue is partly resolved after I set the kotlin-reflect and kotlin sdk version to same number, 1.8.21. Previously it was 1.9 and 1.8.21 respectively. Now
KotlinJsonAdapterFactory
respects only@Json
or@param:Json
for both obfuscated and non-obfuscated build. That is, it looks for the@Json
annotation only in the constructor parameter and not at the field declaration. Now I will have to change all of the existing@field:Json
to either@Json
or@param:Json
Beta Was this translation helpful? Give feedback.
All reactions