2016-10-07 7 views
0

私のモデルクラスではArrayListのプライベートフィールドを持っていますが、BeanUtilsを使用してArrayListを取得しようとすると、そのようなメソッドはありません。なぜこれが起こっているのか説明する次のようにモデルクラスからarraylistオブジェクトを取得するBeanUtils

コードは次のとおりです。

public class ApplicationListDTO implements DTO { 

    private Integer count = null;  
    private String next = null;  
    private String previous = null;  
    private List<ApplicationInfoDTO> list = new ArrayList<ApplicationInfoDTO>(); 
    private long lastUpdatedTime = 0L; 
    private long createdTime = 0L; 

    /** 
    * gets and sets the lastUpdatedTime for ApplicationListDTO 
    **/ 
    @org.codehaus.jackson.annotate.JsonIgnore 
    public long getLastUpdatedTime(){ 
    return lastUpdatedTime; 
    } 
    public void setLastUpdatedTime(long lastUpdatedTime){ 
    this.lastUpdatedTime=lastUpdatedTime; 
    } 

    /** 
    * gets and sets the createdTime for a ApplicationListDTO 
    **/ 

    @org.codehaus.jackson.annotate.JsonIgnore 
    public long getCreatedTime(){ 
    return createdTime; 
    } 
    public void setCreatedTime(long createdTime){ 
    this.createdTime=createdTime; 
    } 

    /** 
    * Number of applications returned.\n 
    **/ 
    @ApiModelProperty(value = "Number of applications returned.\n") 
    @JsonProperty("count") 
    public Integer getCount() { 
    return count; 
    } 
    public void setCount(Integer count) { 
    this.count = count; 
    } 

    /** 
    * Link to the next subset of resources qualified.\nEmpty if no more resources are to be returned.\n 
    **/ 
    @ApiModelProperty(value = "Link to the next subset of resources qualified.\nEmpty if no more resources are to be returned.\n") 
    @JsonProperty("next") 
    public String getNext() { 
    return next; 
    } 
    public void setNext(String next) { 
    this.next = next; 
    } 

    /** 
    * Link to the previous subset of resources qualified.\nEmpty if current subset is the first subset returned.\n 
    **/ 
    @ApiModelProperty(value = "Link to the previous subset of resources qualified.\nEmpty if current subset is the first subset returned.\n") 
    @JsonProperty("previous") 
    public String getPrevious() { 
    return previous; 
    } 
    public void setPrevious(String previous) { 
    this.previous = previous; 
    } 

    /** 
    **/ 
    @ApiModelProperty(value = "") 
    @JsonProperty("list") 
    public List<ApplicationInfoDTO> getList() { 
    return list; 
    } 
    public void setList(List<ApplicationInfoDTO> list) { 
    this.list = list; 
    } 
} 

と、次のようにメソッド呼び出しのためのコードは次のとおりです。

Object object = ((ResponseImpl) message.getContent(List.class).get(0)).getEntity(); 
BeanUtils.getProperty(object,"list"); 

答えて

0

BeanUtils.getProperty(..)returns String、それはあなたが必要なものではありませんので。

あなたは、任意のサポートライブラリなしでそれを行うことができます。

try { 
    Object object = ((ResponseImpl) message.getContent(List.class).get(0)).getEntity(); 
    Field field = object.getClass().getDeclaredField("list"); 

    List<Object> list = field.get(object); 

    [...] 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

それともApache Commons Lang libraryからFieldUtilsでそれを行うことができます。ここに例があります:

try { 
    Object object = ((ResponseImpl) message.getContent(List.class).get(0)).getEntity(); 
    Field field = FieldUtils.getField(object.getClass(), "list", true); 

    List<Object> list = field.get(object); 

    [...] 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
関連する問題