JAXBElements to Java Types?

Help
Anonymous
2009-12-21
2013-05-13
  • Anonymous - 2009-12-21

    Hi,

    I'm trying (with Dozer) to convert a JAXB DTO to a POJO (well, actually, to a JPA-annotated Hibernate entity before persisting it). The problem right now is that right now Dozer does not seem to convert elements from the JAXB JAXBElement<> type to the JAXBElement.getValue() type. So, for example, a JAXBElement<String> s is translated to the POJO as JAXBElement, not java.lang.String. Property names are common; the JAXBElement wrapper is the only difference.

    Is there an easy way to do this without writing a custom converter to handle JAXB->java type transition? It seems like a straightforward thing, so I feel I must be missing something. The Dozer FAQ mentions only POJO->JAXB, not the other way around…

    Thanks for your help!

     
  • dmitry (lv)

    dmitry (lv) - 2009-12-21

    Hi,

    Please write a new feature request. Preferably with example of how you expect it to behave.
    Dozer is lacking several things if compared to latest JAXB specification.

    We will try to make it to January release with other JAXB related feature requests.

    Thanks,
    Dmitry

     
  • Anonymous - 2009-12-22

    Thanks; I created a feature request number 2919058.  Appreciate your help.  If this could make it into the next release, that would be great.

     
  • Rafi

    Rafi - 2011-12-03

    Unable to map deep mapping from Source class to Target class SourceEmployee.Address.houseName to TargetEmployee.houseName

    public class SourceEmployee
    {  
        private String empName;
        private Address addr;

        enter code here

        @Mapping("empName")
        public String getEmpName() {
            return empName;
        }
        public void setEmpName(String empName) {
            this.empName = empName;
        }  
        public Address getAddr() {
            return addr;
        }

        public void setAddr(Address addr) {
            this.addr = addr;
        }  
    }
    address class

    public class Address
    {
        private String houseName;
        public String getHouseName() {
            return houseName;
        }
        public void setHouseName(String houseName) {
            this.houseName = houseName;
        }
    }
    target object

    public class TargetEmployee
    {

        private String empName;
        private String houseName;

        public String getHouseName() {
            return houseName;
        }
        public void setHouseName(String houseName) {
            this.houseName = houseName;
        }
        public String getEmpName() {
            return empName;
        }
        public void setEmpName(String empName) {
            this.empName = empName;
        }
    }
    Main class copying from source to destination

    public class CopyAttributes
    {

        public static void main(String args)
        {
            SourceEmployee sourceEmp = new SourceEmployee();
            sourceEmp.setEmpName("Rafi");

            Address adr = new Address();       
            adr.setHouseName("Aashiyana");
            sourceEmp.setAddr(adr);

            Mapper mapper = new DozerBeanMapper();
            TargetEmployee destObject = mapper.map(sourceEmp, TargetEmployee.class);

            System.out.println(destObject.getEmpName());
            System.out.println(destObject.getHouseName());

        }
    }

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks