Java BeanUtils从arraylist检索对象属性

Java BeanUtils从arraylist检索对象属性,java,apache-commons-beanutils,Java,Apache Commons Beanutils,我正在使用BeanUtils,是否可以检索包含对象属性的arraylist的值。我把代码贴在下面。是否可以检索包含消息对象属性的arraylist。我使用getArrayProperty检索字符串列表,是否可以检索对象列表 public class Message { private String text; private List<Message> messages = new ArrayList<Message>(); public S

我正在使用BeanUtils,是否可以检索包含对象属性的arraylist的值。我把代码贴在下面。是否可以检索包含消息对象属性的arraylist。我使用getArrayProperty检索字符串列表,是否可以检索对象列表

public class Message {

    private String text;

    private List<Message> messages = new ArrayList<Message>();

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public List<Message> getMessages() {
        return messages;
    }

    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }
}
公共类消息{
私有字符串文本;
私有列表消息=新的ArrayList();
公共字符串getText(){
返回文本;
}
公共void setText(字符串文本){
this.text=文本;
}
公共列表getMessages(){
返回消息;
}
公共消息(列出消息){
this.messages=消息;
}
}

提前谢谢。

你试过上课了吗

org.apache.commons.beanutils.PropertyUtilsBean

那个类有这个方法

public Object getProperty(Object bean,
                          String name)
                   throws IllegalAccessException,
                          InvocationTargetException,
                          NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
您应该传递“消息”并对列表进行强制转换

请尝试并检查此链接