【问题标题】:Retrofit Gson serialization not working properly on Samsung S9 device改造 Gson 序列化在三星 S9 设备上无法正常工作
【发布时间】:2019-12-02 16:28:59
【问题描述】:

使用改造 2 和自定义 Gson 转换器,我在特定设备 (Samsung Galaxy s9) 的 api 端点处遇到序列化问题。以下是我的 Gson 配置;

new Builder()
        .baseUrl(API_BASE_URL)
        .addConverterFactory(GsonConverterFactory.create(getGson()));

public static Gson getGson() {

    return new GsonBuilder()
        .setDateFormat(GSON_DATE_FORMAT)
        .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
        .registerTypeAdapter(Long.class, new LongTypeAdapter())
        .setLongSerializationPolicy( LongSerializationPolicy.STRING )
        .create();
}

使用 Sony Xperia 高级版进行测试,对象按应有的方式到达 api,例如:

{
    client_id: '07cffbe0-6df9-4b08-a524-f19b265c17be',
    country: 'xxxx',
    email: 'xxxx',
    first_name: 'xxxx',
    last_name: 'xxxx',
    ....
}

但在三星 Galaxy S9 上我得到:

{
    a: '07cffbe0-6df9-4b08-a524-f19b265c17be',
    b: 'xxxx',
    c: 'xxxx',
    d: 'xxxx',
    e: 'xxxx',
    ....
}

为什么序列化会在不同的设备上发生变化?

【问题讨论】:

    标签: android serialization gson retrofit


    【解决方案1】:

    似乎在其中一台设备上启用了 proguard / 混淆,而在另一台设备上禁用了,您确定在两台设备上使用相同的构建吗?

    关于混淆和 GSON 的问题,请看这里:https://stackoverflow.com/a/31851024/2879657

    【讨论】:

    • 就是这样!三星有签名的发布版本,而另一个是调试版本......干杯伙伴大声笑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2020-09-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多