java - Can I Set Nested Values on MOXy DynamicEntities that are null? -
i using eclipselink moxy dynamic entity creation , having trouble 1 thing. app hold no libraries in codebase downstream soap services. on startup creates of objects using dynamicjaxbcontextfactory.createcontextfromxsd(). here, take own locally defined objects , convert them using metadata in app. if downstream objects simple, no nested classes, can create converted objects no problem. have downstream dynamictype like:
class person { class address { string city; string state; } string first; string last; address address; }
i've tried create person object using set xpath methods:
dynamicentity person = jaxbcontext.newdynamicentity(jaxbcontext.getdynamictype( "person" )); jaxbcontext.setvaluebyxpath( person, "first/text()", null, "tres"); jaxbcontext.setvaluebyxpath( person, "last/text()", null, "bailey"); jaxbcontext.setvaluebyxpath( person, "address/city/text()", null, "cowpens"); jaxbcontext.setvaluebyxpath( person, "address/state/text()", null, "sc");
the first 2 set values work, if person brand new object, latter 2 lines set city , state not set values. makes sense not work, since address object not set value. in use case, trying avoid having service-specific bindings files , not have iterate through each of dynamictypes find fields , type on each setting. possible in moxy?
i use eclipselink version 2.5 , running on tomcat 7 java 6.
note: i'm eclipselink jaxb (moxy) lead , member of jaxb (jsr-222) expert group.
you need following:
jaxbcontext.setvaluebyxpath( person, "first/text()", null, "tres"); jaxbcontext.setvaluebyxpath( person, "last/text()", null, "bailey"); object address = jaxbcontext.createbyxpath(person, "address", null, object.class); jaxbcontext.setvaluebyxpath(person, "address", null, address); jaxbcontext.setvaluebyxpath( person, "address/city/text()", null, "cowpens"); jaxbcontext.setvaluebyxpath( person, "address/state/text()", null, "sc");
i can see behaviour looking in question. mind entering enhancement request using link below:
Comments
Post a Comment