【发布时间】: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