首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Dozer中使用params转换具有一个getter的j8583对象

在Dozer中使用params转换具有一个getter的j8583对象
EN

Stack Overflow用户
提问于 2015-12-10 22:36:07
回答 2查看 237关注 0票数 0

我有一个IsoMessage对象(https://github.com/chochos/j8583/blob/master/src/main/java/com/solab/iso8583/IsoMessage.java),它有一个内部数组,只能通过getField(int)方法访问。

代码语言:javascript
复制
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];
    }

我需要通过调用getField(param )来读取字段数组中存储的所有属性,并将它们移动到一个具有Map的新对象,并希望使用dozer实现这一点。

我需要翻译的对象:

代码语言:javascript
复制
public class TransactionInstance implements Serializable {

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

我正在试验这个推土机配置,希望从我的isoMessage对象中获得字段1。

代码语言:javascript
复制
<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>

但是,除了这个例外,我无法从原始对象中获取值:

代码语言:javascript
复制
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)

我正在检查这个帖子,https://github.com/DozerMapper/dozer/issues/111 to Dozer field mapping?总线仍然卡在同一个地方,我还想知道我是否可以通过API来实现这一点,这样我就可以动态地知道我想从原始bean获取哪些字段。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-16 01:17:50

最后,我使用dozer直接访问内部对象(http://dozer.sourceforge.net/documentation/custommethods.html)的能力完成了严格的映射。

代码语言:javascript
复制
<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>
票数 0
EN

Stack Overflow用户

发布于 2015-12-11 17:13:19

我不熟悉Dozer,但字段1是位图。getField(1)返回null

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34212987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档