私は 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 Number) を呼び出して、fields 配列に保存されているすべての属性を読み取り、それらを Map を持つ新しいオブジェクトに移動する必要があり、dozer を使用してこれを実現したいと考えています。
翻訳する必要があるオブジェクト:
public class TransactionInstance implements Serializable {
private static final long serialVersionUID = 3429335891821913088L;
private String transactionName;
private Map<String, String> parameters;
isoMessage オブジェクトからフィールド 1 を取得することを期待して、この dozer 構成を試していました。
<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 and How to pass `this` to Dozer field mapping? バスはまだ同じ場所でスタックしています。また、API を使用してこれを達成できるかどうか疑問に思っていたので、元の Bean から取得するフィールドを動的に伝えることができます