Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用Kotlin默认值的Jackson反序列化失败_Android_Kotlin_Jackson_Proguard - Fatal编程技术网

Android 使用Kotlin默认值的Jackson反序列化失败

Android 使用Kotlin默认值的Jackson反序列化失败,android,kotlin,jackson,proguard,Android,Kotlin,Jackson,Proguard,我正在使用Jackson来反序列化来自改型的Json响应 我用图书馆来做这件事 对于Java表示为原语的一些值,我有一些带有默认值的数据类,因此在没有空检查的情况下访问它时不会崩溃 这一切在debug模式下都可以正常工作,但当我在启用proguard的情况下运行release时,默认值未设置,这些值为空,导致我的应用程序在从Java原语访问它们时崩溃 我试着添加我在网上能找到的每一条proguard规则,但没有成功 如果有人有任何想法,请分享 谢谢 数据类的示例 data class RideT

我正在使用Jackson来反序列化来自改型的Json响应

我用图书馆来做这件事

对于Java表示为原语的一些值,我有一些带有默认值的数据类,因此在没有空检查的情况下访问它时不会崩溃

这一切在
debug
模式下都可以正常工作,但当我在启用proguard的情况下运行
release
时,默认值未设置,这些值为空,导致我的应用程序在从Java原语访问它们时崩溃

我试着添加我在网上能找到的每一条proguard规则,但没有成功

如果有人有任何想法,请分享

谢谢

数据类的示例

data class RideTask(@JsonProperty(RiderFrontendConsts.PARAM_LOCATION)
                    val location: UserVisibleLocation?,

                    @JsonProperty(RiderFrontendConsts.PARAM_ETA_TS)
                    val etaTime: Double?,

                    @JsonProperty(RiderFrontendConsts.PARAM_TIME_TO_COMPLETION)
                    val timeToCompletion: Double?,

                    @JsonProperty(RiderFrontendConsts.PARAM_ETA_DESCRIPTION)
                    val etaDescription: String?,

                    @JsonInclude(JsonInclude.Include.NON_NULL)
                    @JsonProperty(RiderFrontendConsts.PARAM_INTERNAL_ETA_TS)
                    val internalEta: Long? = 0,

                    @JsonProperty(RiderFrontendConsts.PARAM_ETA_DESCRIPTION_LIST)
                    val etaDescriptionList: List<String>?,

                    @JsonProperty(RiderFrontendConsts.PARAM_DESCRIPTION_PREFIX)
                    val descriptionPrefix: String?,

                    @JsonProperty(RiderFrontendConsts.PARAM_WALKING_DISTANCE_DESCRIPTION)
                    val walkingDistanceDescription: String?,

                    @JsonProperty(RiderFrontendConsts.PARAM_WALKING_DISTANCE_IN_METERS)
                    val walkingDistanceInMeters: Int? = 0)
    : Serializable
相关专业警卫规则

#parsers
-keep class com.fasterxml.jackson.annotation.** { *; }
-dontwarn com.fasterxml.jackson.databind.**

# Kotlin
-keep class kotlin.Metadata { *; }
-keepclassmembers public class via.rider.frontend.** {
    public synthetic <methods>;
}
#解析器
-保留类com.fasterxml.jackson.annotation.*{*;}
-dontwarn com.fasterxml.jackson.databind**
#科特林
-保持类kotlin.Metadata{*;}
-keepclassmembers公共类通过.rider.frontend.*{
公共合成;
}

您需要保留数据类文件(RideTask的包-我的示例假设RideTask所在的dto包),类似于以下内容:

-keep,includedescriptorclasses class via.rider.dto.** { *; }

如果这还不能解决问题,请发布一个包含解析错误的日志猫。

认为问题在于必须添加一个规则才能保留字段名,例如

-keep class your.package.model.** { <fields>; }
-保留类的.package.model.*{;}

我来自后端领域,那里没有任何类型的proguard,但为了让Jackson使用Kotlin的东西,我必须添加到类路径中,并从那里调用
val mapper=ObjectMapper().registerKotlinModule()
扩展函数。希望这有帮助。谢谢@oleg,我已经在用了。这绝对是pro guard的功能,因为它在没有它的情况下工作得很好,而且OP没有响应,我也遇到了完全相同的问题,这并不能解决我的问题。我得到以下异常:
kotlin.reflect.jvm.internal.KotlinReflectionInternalError:此可调用函数不支持默认调用:公共构造函数MyConstructor…
看起来这可能有一个解决方法:
-keep class your.package.model.** { <fields>; }