commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alfonso Mateos <gcalf...@gmail.com>
Subject [beanutils] recursive populate does not instantiate nested properties from Map to my bean
Date Mon, 15 Dec 2014 12:12:43 GMT
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?

thanks in advance :-)

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