1

BeanUtils copyProperties は、そのままでは、ブール オブジェクト プロパティからブール プリミティブ プロパティへのコピーを処理していないようです。

これを処理するコンバーターを作成して登録できると考えましたが、うまくいかなかったようです。

では、BeanUtils を使用してプロパティをクラス Source からクラス Destination にコピーするにはどうすればよいでしょうか。

public class Destination {

    private boolean property;

    public boolean isProperty() {
        return property;
    }

    public void setProperty(boolean property) {
        this.property = property;
    }
}


public class Source{

    private Boolean property;

    public Boolean getProperty() {
        return property;
    }

    public void setProperty(Boolean property) {
        this.property = property;
    }
}
4

3 に答える 3

2
try creating both 
/*by default beanutils copyproperties looks for below method if you use either apache or spring flavour of beanutils.
always prefer using apache 1.9.2 ( fixed many bugs) but bit slow compared with spring beanutils.*/
 public Boolean getProperty() {
        return property;
    }
//which is used by some frameworks 
 public Boolean isProperty() {
        return property;
    }
于 2015-10-31T00:39:00.593 に答える
0
public class Destination {
    private boolean property;

    // code getProperty() instead
    public boolean isProperty() {
        return property;
    }

    public void setProperty(boolean property) {
        this.property = property;
    }
}
于 2010-05-28T08:39:40.073 に答える
0

実際にはその逆です。

public static void main(String[] args) throws Exception {
    Source d = new Source();
    d.setProperty(Boolean.TRUE);
    BeanMap beanMap = new BeanMap(d);

    Destination s = new Destination();
    BeanUtils.populate(s, beanMap);
    System.out.println("s.getProperty()=" + s.isProperty());
}
于 2009-03-05T13:59:45.593 に答える