commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Hussein <>
Subject BEAN UTILS : dealing with enumerations
Date Tue, 10 Mar 2009 17:17:27 GMT

I have a bean with an internal Enum

public class NewEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    public enum Type { One, Two, Three }

    private Type type;

    public Type getType() {
        return type;

    public void setType(Type type) {
        this.type = type;

In my application I have a handle to the bean, and the method name and value
as strings


Object bean = new NewEntity();
String name = "type";
String value = "One";

when I call setProperty

 BeanUtils.setProperty(bean, "type", "One" );

I get :

Exception in thread "main" java.lang.IllegalArgumentException: Cannot invoke
javaapplication1.NewEntity.setType on bean class 'class
javaapplication1.NewEntity' - argument type mismatch - had objects of type
"java.lang.String" but expected signature "javaapplication1.NewEntity$Type"

But when I call

         BeanUtils.setProperty(bean, "type", NewEntity.Type.One );

all is ok.

Is there some way to set a property on a bean that is an Enum with just the
string name, without calling methods on the bean enum type directly, as I
dont have these handles, just the name and value as strings ??



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message