1.

Why Do I Get Classcastexception When Accessing Nested Maps?

Answer»

SAY you have a map which contains a NESTED map ala: nestedmap.put ("key2", "somevalue"); map.put ("key1", nestedmap);

If you use the following syntax: String VAL = PropertyUtils.getProperty(bean, "map(key1)(key2)");

It will actually return "map(key1)", which will be a Map, not a String.

BeanUtils uses '.' as a property separator, and the second property should actually USED mapped syntax, since it is directly accessing a map now, thus the correct USAGE should be: String val = PropertyUtils.getProperty(bean, "map(key1).key2");

Say you have a map which contains a nested map ala: nestedmap.put ("key2", "somevalue"); map.put ("key1", nestedmap);

If you use the following syntax: String val = PropertyUtils.getProperty(bean, "map(key1)(key2)");

It will actually return "map(key1)", which will be a Map, not a String.

BeanUtils uses '.' as a property separator, and the second property should actually used mapped syntax, since it is directly accessing a map now, thus the correct usage should be: String val = PropertyUtils.getProperty(bean, "map(key1).key2");



Discussion

No Comment Found