简体   繁体   English

Jackson mapper 在三星 SM-T580 上抛出“冲突的 setter 定义”

[英]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.classsetContent方法。 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.不幸的是,我仍然不知道为什么映射器试图在这个特定设备上实例化PaintHoverPopupView类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jackson ObjectMapper冲突的setter定义(Android.Graphics.Bitmap) - Jackson ObjectMapper Conflicting setter definitions (Android.Graphics.Bitmap) 属性“ thenComparing”的setter定义冲突: - Conflicting setter definitions for property “thenComparing”: org.codehaus.jackson.map.JsonMappingException:属性“ matchColumn”的设置器定义冲突:com.sun.rowset.JdbcRowSetImpl - org.codehaus.jackson.map.JsonMappingException: Conflicting setter definitions for property “matchColumn”: com.sun.rowset.JdbcRowSetImpl 无法读取 JSON:属性的设置器定义冲突 - Could not read JSON: Conflicting setter definitions for property Lombok 和 jackson - 冲突/不明确的属性名称定义 - Lombok and jackson - Conflicting/ambiguous property name definitions 与 iText7 一起使用时属性的 setter 定义冲突 - Conflicting setter definitions for property when using with iText7 使用Jackson 2.9.6的运动衫中的属性名称定义冲突 - Conflicting property name definitions in jersey ,using Jackson 2.9.6 如何在不访问源代码的情况下解决 jackson 中属性的冲突 getter 定义 - How to solve conflicting getter definitions for property in jackson without access to source Jackson CSV映射器不适用于自定义架构 - Jackson CSV mapper doesn't work for custom schema Java泛型和杰克逊映射器 - Java generics and jackson mapper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM