2016-10-07 14 views
0

를 사용하여 모델 클래스에서의 ArrayList 오브젝트를 취득 왜 이런 일이 일어 났는지 설명해 주시겠습니까? 다음과 같이누군가가 친절하게도 주시기 바랍니다 수 있습니다, I 타입 <code>ArrayList</code>의 개인 필드가 내 모델 클래스에서 평민에게 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(); 
}