2009-03-05 2 views
1

BeanUtils copyProperties는 부울 객체 속성에서 부울 기본 속성으로의 복사를 처리하지 않는 것 같습니다.BeanUtils copyProperties를 사용하여 부울에서 부울로 복사하는 방법은 무엇입니까?

나는 이것을 처리하기 위해 변환기를 생성하고 등록 할 수 있다고 생각했지만, 그것은 효과가없는 것처럼 보였다. 그래서

은 어떻게 클래스 대상에 클래스 소스에서 속성을 복사 할 BeanUtils를 사용할 수있는 곳 :

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; 
    } 
} 
+0

I 이거 붙어있어. 만약 당신이 할 수 있었다면 Plz는 응답을 'carrier'라고 덧붙입니다. –

답변

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()); 
} 
0
public class Destination { 
    private boolean property; 

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

    public void setProperty(boolean property) { 
     this.property = property; 
    } 
} 
1
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; 
    } 
+0

우리가 가지고있는 것처럼 아파치 beanutils를 사용할 때 변환기를 사용해야합니다 ConvertUtils.register (new DateConverter (null), java.util.Date.class); – RamPrakash