Search code examples
javaparsingreflectiondtopojo

How to parse DTO to Pojo objects


Well, I'm trying to parse objects and I'm having so much issues. My classes are like this:

-Entidad-

public class Entidad{

    private Long codEntidad;
    private Set<Comunicacion> comunicacion;


    /*------------ Getter and Setters --------------*/

}

-Comunicacion-

public class Comunicacion {

    private Entidad entidad;
    private Long codComunicacion;

    /*------------ Getter and Setters --------------*/

}

I need to parse to DTO objects:

-EntidadDTO-

public class EntidadDTO{

    private Long codEntidad;
    private Set<ComunicacionDTO> comunicacionDto;


    /*------------ Getter and Setters --------------*/

}

-ComunicacionDTO-

public class ComunicacionDTO {

    private EntidadDto entidadDto;
    private Long codComunicacion;

    /*------------ Getter and Setters --------------*/

}

I tried to use:

BeanUtils.copyProperties(entidad, entidadDto);

It seems that the parse is success but the property entidadDto.getComunicacionDto(); is a hashMap of Comunicacion (not ComunicacionDTO)

Should I try to make a custom parse with reflection?

Also I'd like to use this to parse more objects with a similar structure. Thanks!


Solution

  • Try dozer. You can define mappings from bean to bean using it. http://dozer.sourceforge.net/