yigityus / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Mixing primitive and wrapper types in getter/setter leads to getter/setter aren't paired #147

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

    public static void main(String[] args) {
        DefaultMapperFactory factory = new DefaultMapperFactory.Builder().
                mapNulls(true).
                build();
        factory.registerClassMap(factory.classMap(A.class, B.class)
                .field("c.id", "someId")
                .byDefault()
                .toClassMap());

        A a = new A();
        a.setC(new C());
        a.getC().setId(12L);
        B b = new B();

        MapperFacade mapperFacade = factory.getMapperFacade();
        mapperFacade.map(a, b);

        System.out.println(b.getSomeId());
    }

    public static class A {
        private C c;

        public C getC() {
            return c;
        }

        public void setC(C c) {
            this.c = c;
        }
    }

    public static class B {
        private long someId;

        public Long getSomeId() {
            return someId;
        }

        public void setSomeId(long id) {
            this.someId = id;
        }
    }

    public static class C {
        private Long id;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }
    }

What is the expected output? What do you see instead?
Expected 12, actual value null

What version of the product are you using? On what operating system?
1.4.3, Linux

Please provide any additional information below.

Please notice getSomeId/setSomeId types

        public Long getSomeId() {
            return someId;
        }

        public void setSomeId(long id) {
            this.someId = id;
        }

Original issue reported on code.google.com by alex.che...@gmail.com on 22 Feb 2014 at 2:19

GoogleCodeExporter commented 8 years ago
Mixing primitive/wrapper types actually means that it's not one 'property'; 
even though a Java 5+ compiler could usually handle this particular case with 
auto-boxing, we're using javassist which requires java 1.4 source format.

I think that to solve this problem (in general) we'd have to implement support 
for dual-typed properties; from javassist perspective, long/Long is just as 
different as String/Long...

Original comment by matt.deb...@gmail.com on 9 Mar 2014 at 4:06

GoogleCodeExporter commented 8 years ago
Well, I undestand and even share the javassist's perspective :) I've seen 
couple of times that a newbie "hangs" for an hours with a "strange" NPE with 
such getter/setter pair )

Dual-typed properties for this case sounds like over-engeenering for me. If its 
simple to add hard code for corner case "primitive-wrapper" (maybe warn user 
also?) - I'd vote for fixing - it just may save somebody's time and prove 
framework maturity. If its hard to implement... well... leave it.

Original comment by alex.che...@gmail.com on 10 Mar 2014 at 5:07