[英]Jackson mapper throws “conflicting setter definitions” on Samsung SM-T580
Problem: When converting JSON to an object with Jackson, the following exception is thrown on my Samsung SM-T580 (Android 6.0.1).问题:使用 Jackson 将 JSON 转换为对象时,在我的 Samsung SM-T580 (Android 6.0.1) 上抛出以下异常。 The exception is not thrown on a OnePlus3 (Android 6.0.1) or ZenPad 8.0 (Android 5), only on the Samsung SM-T580.
OnePlus3 (Android 6.0.1) 或 ZenPad 8.0 (Android 5) 不会抛出异常,仅在三星 SM-T580 上抛出。
java.lang.IllegalArgumentException: Conflicting setter definitions for property "myanmarEncoding": android.graphics.Paint#setMyanmarEncoding(1 params) vs android.graphics.Paint#setMyanmarEncoding(1 params)
at [Source: N/A; line: -1, column: -1]
The mapping is performed like the following (Jackson version 2.8.4).映射执行如下(Jackson 版本 2.8.4)。
import com.fasterxml.jackson.databind.ObjectMapper;
...
ObjectMapper objectMapper = new ObjectMapper();
try {
myObj = objectMapper.convertValue(document.getProperties(), MyClass.class);
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage());
return;
}
Approach: First, I've added @JsonIgnoreProperties(ignoreUnknown = true)
to MyClass
.方法:首先,我已将
@JsonIgnoreProperties(ignoreUnknown = true)
到MyClass
。 Then, I've attempted to work around the issue by using @JsonIgnoreType
on the android.graphics.Paint
class via mix in. This was kind of successful because it prevents the first exception.然后,我尝试通过 mix in 在
android.graphics.Paint
类上使用@JsonIgnoreType
来解决这个问题。这有点成功,因为它防止了第一个异常。
Unfortunately, another exception is thrown:不幸的是,抛出了另一个异常:
java.lang.IllegalArgumentException: Conflicting setter definitions for property "content": android.widget.HoverPopupWindow#setContent(1 params) vs android.widget.HoverPopupWindow#setContent(1 params)
at [Source: N/A; line: -1, column: -1]
The method android.graphics.Paint#setMyanmarEncoding
and the class android.widget.HoverPopupWindow
seem to be part of the hidden android sources.方法
android.graphics.Paint#setMyanmarEncoding
和类android.widget.HoverPopupWindow
似乎是隐藏的 android 源的一部分。
What is happening here and how can I solve this problem?这里发生了什么,我该如何解决这个问题?
I've found a workaround by excluding the Paint.class
and ignoring the setContent
methods from the Android-hidden HoverPopupWindow.class
.我找到了一种解决方法,即排除
Paint.class
并忽略 Android 隐藏的HoverPopupWindow.class
的setContent
方法。 The related method parameters were defined in HoverPopupWindow.smali (GitHub).相关方法参数在HoverPopupWindow.smali (GitHub) 中定义。
This is how the mixins are applied (before using objectMapper.convertValue
):这是 mixins 的应用方式(在使用
objectMapper.convertValue
之前):
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixIn(android.graphics.Paint.class, IgnoreType.class);
objectMapper.addMixIn(Object.class, IgnoreMethods.class);
The mixin classes are defined like the following: mixin 类定义如下:
@JsonIgnoreType
public class IgnoreType {}
interface IgnoreMethods {
@JsonIgnore
void setContent(int resId);
@JsonIgnore
void setContent(View view);
@JsonIgnore
void setContent(View view, ViewGroup.LayoutParams lp);
@JsonIgnore
void setContent(CharSequence text);
}
Unfortunately, I still don't know why the mapper tries to instantiate Paint
and HoverPopupView
classes on this specific device.不幸的是,我仍然不知道为什么映射器试图在这个特定设备上实例化
Paint
和HoverPopupView
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.