简体   繁体   English

在推土机中转换具有参数的一个吸气剂的j8583对象

[英]Converting j8583 object having one getter with params in Dozer

I have an IsoMessage object ( https://github.com/chochos/j8583/blob/master/src/main/java/com/solab/iso8583/IsoMessage.java ) that has an internal array which I can only access through a getField(int) method. 我有一个IsoMessage对象( https://github.com/chochos/j8583/blob/master/src/main/java/com/solab/iso8583/IsoMessage.java ),它具有一个内部数组,我只能通过getField(int)方法。

public class IsoMessage {

    @SuppressWarnings("rawtypes")
    private IsoValue[] fields = new IsoValue[129];
    .........
    .........
    .........

    /** Returns the IsoValue for the specified field. First real field is 2. */
    @SuppressWarnings("unchecked")
    public <T> IsoValue<T> getField(int field) {
        return fields[field];
    }

I need to read all the attributes stored on the fields array, by calling getField(param Number), and move them to a new object that has a Map, and want to achieve this using dozer. 我需要通过调用getField(param Number)来读取存储在fields数组中的所有属性,并将它们移到具有Map的新对象中,并希望使用推土机来实现。

the object that I need to translate to: 我需要转换为的对象:

public class TransactionInstance implements Serializable {

    private static final long serialVersionUID = 3429335891821913088L;
    private String transactionName;
    private Map<String, String> parameters;

I was experimenting with this dozer configuration hoping to get the field 1 from my isoMessage object 我正在尝试使用此推土机配置,希望从我的isoMessage对象获取字段1

<mapping map-id="a">
    <class-a>com.solab.iso8583.IsoMessage</class-a>
    <class-b>j8583.example.TransactionInstance</class-b>
    <field>
        <a get-method="getField" key="1">field</a>
        <b map-set-method="put">parameters</b>
    </field>
</mapping>

But I'm stuck at getting the value from the original object with this exception: 但是我一直坚持从原始对象获取值,但有以下例外:

Exception in thread "main" org.dozer.MappingException: No read or write method found for field (field) in class (class com.solab.iso8583.IsoMessage)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.determinePropertyType(GetterSetterPropertyDescriptor.java:319)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyType(GetterSetterPropertyDescriptor.java:76)
    at org.dozer.fieldmap.MapFieldMap.determineActualPropertyType(MapFieldMap.java:170)
    at org.dozer.fieldmap.MapFieldMap.getSrcFieldValue(MapFieldMap.java:95)

I was checking this post https://github.com/DozerMapper/dozer/issues/111 and How to pass `this` to Dozer field mapping? 我正在检查这篇文章https://github.com/DozerMapper/dozer/issues/111以及如何将`this`传递给Dozer字段映射? bus still stuck in the same place, also I was wondering if I can achieve this by using the API so I can tell dynamically which fields I want to get from the original bean 总线仍然停留在同一位置,我也想知道是否可以通过使用API​​来实现这一点,以便可以动态告诉我要从原始bean中获取哪些字段

I'm not familiar with Dozer, but field 1 is the bitmap. 我对推土机不熟悉,但是字段1是位图。 getField(1) returns null . getField(1)返回null

I finally foud the rigth mapping using the capability that dozer has to access the internal objects directly ( http://dozer.sourceforge.net/documentation/custommethods.html ). 最后,我使用了推土机必须直接访问内部对象( http://dozer.sourceforge.net/documentation/custommethods.html )的功能来进行精确映射。

<mapping>
    <class-a is-accessible="true">com.solab.iso8583.IsoMessage</class-a>
    <class-b>j8583.example.TransactionInstance</class-b>
    <field>
        <a>fields[3]</a>
        <b set-method="addParameter" map-set-method="addParameter" key="field3">parameters
        </b>
    </field>

</mapping>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM