commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <brit...@apache.org>
Subject Re: [beanutils] recursive populate does not instantiate nested properties from Map to my bean
Date Tue, 16 Dec 2014 15:27:33 GMT
2014-12-15 13:12 GMT+01:00 Alfonso Mateos <gcalfons@gmail.com>:
>
> Hi guys,
>
> I can execute the following code:
>
> I've got the following bean:
>
>         RecruitingPersonDto rPersonDto = new RecruitingPersonDto();
>
>         rPersonDto.setProcessInstanceId("pid-000-1");
>
>         TgssPersonDtoAudited tgssPersonDtoAudited = new
> TgssPersonDtoAudited();
>
>         tgssPersonDtoAudited.setId("27");
>
>         tgssPersonDtoAudited.setBirthday(new LocalDate(2014, 12, 31));
>
>         rPersonDto.setTgssPersonDtoAudited(tgssPersonDtoAudited);
>
>
> Then I get a Map from my bean, this is done without a glitch:
>
>         LocalDateConverter converter = new
> LocalDateConverter("yyyy-MM-dd");
>
>         ConvertUtils.register(converter, LocalDate.class);
>
>
> Then I try to recover its contents to another bean:
>
>         RecruitingPersonDto rPersonDto2 = new RecruitingPersonDto();
>
>         rPersonDto2.setTgssPersonDtoAudited(new TgssPersonDtoAudited());
>
>         BeanUtilsBean.getInstance().getConvertUtils().register(converter,
> LocalDate.class);
>
>         BeanUtilsBean.getInstance().populate(rPersonDto2, lHashMap);
>
> This also works fine. But if I skip the explicit instantiation of the
> nested bean "TgssPersonDtoAudited" then it fails. I mean: the code:
>
>         RecruitingPersonDto rPersonDto2 = new RecruitingPersonDto();
>
>         BeanUtilsBean.getInstance().getConvertUtils().register(converter,
> LocalDate.class);
>
>         BeanUtilsBean.getInstance().populate(rPersonDto2, lHashMap);
>
> Will fail because it complains because the property
> rPersonDto2.getTgssPersonDtoAudited() returns null, it seems unable to
> create a new instance automatically when it's needed from inside of the
> populate method...
>
> How could I get beanutils to populate my target dto but insantiating nested
> properties when needed?
>

Hello Alfonso,

this is currently not possible with BeanUtils. If your only using BeanUtils
for coping properties, maybe the dozer framework [1] can do the trick for
you.

Regards,
Benedikt

[1] http://dozer.sourceforge.net/


>
> thanks in advance :-)
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

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