1

We are using JPA Entities to get the database rows and then when we transfer that to the external, we want to use disconnected object (DTO) which are simple beans annotated with JAX-B.

We use a mapper and its code looks like this:

public BillDTO map(BillEntity source, BillDTO target) {
    BeanUtils.copyProperties(source, target);
    return target;
}

But when the code is running we get an error like this:

java.lang.IllegalArgumentException: argument type mismatch

Note this is the Spring implementation of the BeanUtils:

import org.springframework.beans.BeanUtils

And the naming of the properties are identical (with their getter/setter).

  • Anybody knows why the error happens?

  • And how to use a fast way instead just copying properties one by one?

4

1 に答える 1

2

この例はうまく機能しています。ここでStringプロパティはプロパティにコピーされenumます:

実在物:

public class A {
   private String valueFrom;

   public String getValue() {
      return valueFrom;
   }

   public void setValue(String value) {
      this.valueFrom = value;
   }
}

DTO (Enは列挙型):

public class B {
   private En valueTo;

   public void setValue(String def) {
      this.valueTo = En.valueOf(def);
   }
   
   public void setEnumValue(En enumVal) {
      this.valueTo = enumVal;
   }
}

あなたのGitHubの例に関してはclass B、ゲッターの問題は次のようになります。

public String getValue()

例:

public String getValue() {
   return value.toString();
}
于 2013-07-11T13:13:13.290 に答える