我有一个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];
}我需要通过调用getField(param )来读取字段数组中存储的所有属性,并将它们移动到一个具有Map的新对象,并希望使用dozer实现这一点。
我需要翻译的对象:
public class TransactionInstance implements Serializable {
private static final long serialVersionUID = 3429335891821913088L;
private String transactionName;
private Map<String, String> parameters;我正在试验这个推土机配置,希望从我的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>但是,除了这个例外,我无法从原始对象中获取值:
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获取哪些字段。
发布于 2015-12-16 01:17:50
最后,我使用dozer直接访问内部对象(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>发布于 2015-12-11 17:13:19
我不熟悉Dozer,但字段1是位图。getField(1)返回null。
https://stackoverflow.com/questions/34212987
复制相似问题