简体   繁体   中英

BeanUtils to retrieve the Objects property from arraylist

I am using the BeanUtils, is it possible to retrieve the value of the arraylist containing object properties. I posted the code below. Is it possible to retrieve the arraylist containning message object property. I used the getArrayProperty to retrieve the list of string, is it possible to retrieve the list of object?

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

Thanks in advance.

Have you tried with the class

org.apache.commons.beanutils.PropertyUtilsBean

that class have the method.

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.

You should pass "messages" and do a cast to the List

Give a try and check this link

http://commons.apache.org/proper/commons-beanutils/javadocs/v1.8.3/apidocs/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM