java - Anonymous inner classes JAXB serialization -


i tried use anonymous inner classes initializers syntax serialize jaxb generated objects, , noticed works on endpoints not resttemplate. wondering why working in 1 case , not other?

to give example, sample endpoint in spring returns jaxb generated profile instance:

@payloadroot(namespace = namespace_uri, localpart = service_name) @responsepayload public profile getprofile(@requestpayload  getprofile request) {      // stuff service returns profile     return service.dostuff(request);  } 

now, when have service returning anonymous instance of profile, there no serialization issues:

return new profile() {      {         setbirthday(user.getbirthday());         setemailaddress(user.getemailaddress());         setfirstname(user.getfirstname());         setgender(user.getgen());         // , on     } };   

however, when try use anonymous inner classes argument resttemplate, jaxb error regarding not supported anonymous classes.

"a non-static inner class, , jaxb can't handle those. problem related following location..."

    private updateprofile createupdateprofilerequest(final updateprofile request) {       return new updateprofile() {          {             setprofilev2(getprofile(request));         }     };  }   private profilev2 getprofile(updateprofile request) {      profilev2 profile = new profilev2();      profileupdate profileupdate = request.getprofileupdate();      profile.setbirthday(profileupdate.getbirthday());     profile.setfirstname(profileupdate.getfirstname());       return profile;  } 

i have read post: what double brace initialization in java?

and don't have use case these objects turn container managed singletons - memory leaks.

there mention of serialization issues, no details , understand this.

since using jaxb serialization on endpoints too, why possible jaxb serialize such objects outgoing data on endpoints not within resttemplate.postforobject(...).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -