Proguard导致Jackson错误 [英] Proguard causes Jackson error
问题描述
启用Proguard规则后,我面临以下问题 因此,在将任何内容发送到网络之前都会出现错误.
After enabling proguard rules I faced with the following So error come before sending anything to network.
java.lang.RuntimeException:无法转换 FormDocTankPermission到RequestBody
java.lang.RuntimeException: Unable to convert FormDocTankPermission to RequestBody
由
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:否 找到类FormDocTankPermission的序列化器,没有属性 发现创建BeanSerializer(为避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class FormDocTankPermission and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
我以@Retrofit.Body
的形式发送的课程如下所示:
My class that I send as @Retrofit.Body
look like following:
class FormDocTankPermission (
@get:JsonProperty("fuelCardId")
val fuelCardId: Long,
@get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
@get:JsonProperty("validityDate")
val validityDate: Date
)
我认为@get:JsonProperty
会导致问题
I assume that somehow @get:JsonProperty
causes ISSUE
我像这样cretea翻新
I cretea Retrofit like this
Builder()
.[...]
.addConverterFactory(JacksonConverterFactory.create())
杰克逊的Proguard规则
Proguard rules for Jackson
# Jackson
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
推荐答案
Proguard可能会删除自定义序列化器/反序列化器的默认构造函数. 在这种情况下,该规则对我有帮助:
Proguard may remove default constructor of custom serializers/deserializers. That rules help me in such case:
-keepclassmembers class ** extends com.fasterxml.jackson.databind.ser.std.** {
public <init>(...);
}
-keepclassmembers class ** extends com.fasterxml.jackson.databind.deser.std.** {
public <init>(...);
}
这篇关于Proguard导致Jackson错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!