commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dean Wang (JIRA)" <>
Subject [jira] [Created] (BEANUTILS-467) Option to automatically convert map to nested bean class
Date Sun, 21 Sep 2014 20:59:33 GMT
Dean Wang created BEANUTILS-467:

             Summary: Option to automatically convert map to nested bean class
                 Key: BEANUTILS-467
             Project: Commons BeanUtils
          Issue Type: Improvement
          Components: Bean / Property Utils
    Affects Versions: 1.8.3
            Reporter: Dean Wang
            Priority: Minor

BeanUtils.populate(Class, Map) does not convert nested field of Map to Bean class. The current
Convert interface doesn't support generic convert for Map to Bean.

A simple example, I have the following class definition:
class A {
  int val;
class B {
  A a;
and the following Map definition:
Map<String, Object> jsonOfB = {
  "A" = Map<String, Object> {
    "val" = 1
I would like to get the instance of B as following when I use {{BeanUtils.populate(jsonOfB,
b.a.val == 1

Currently, this kind of scenario is not considered, so BeanUtils tries to set field {{a}}
in class {{B}} with Map, and failed as {{Caused by: java.lang.IllegalArgumentException: argument
type mismatch}}

Use case: I use json converter to convert json string and java class. Usually I use Map<String,
Object> as the destination type when converting json string so that I need not define multiple
Java class just to capture minor json structure differences. To extend, I also create new
object from part of the json Map.

I see a possible change could be made in {{org.apache.commons.beanutils.PropertyUtilsBean#setNestedProperty}}

This message was sent by Atlassian JIRA

View raw message