You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dean Wang (JIRA)" <ji...@apache.org> on 2014/09/21 22:59:33 UTC

[jira] [Created] (BEANUTILS-467) Option to automatically convert map to nested bean class

Dean Wang created BEANUTILS-467:
-----------------------------------

             Summary: Option to automatically convert map to nested bean class
                 Key: BEANUTILS-467
                 URL: https://issues.apache.org/jira/browse/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:
{quote}
class A {
  int val;
}
class B {
  A a;
}
{quote}
and the following Map definition:
{quote}
Map<String, Object> jsonOfB = {
  "A" = Map<String, Object> {
    "val" = 1
  }
}
{quote}
I would like to get the instance of B as following when I use {{BeanUtils.populate(jsonOfB, b):}}
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
(v6.3.4#6332)