Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB marshaller no-arg default constructor

Tags:

java

jaxb

I would like to marshalling a java object from a java library.

When marshalling a java object using JAXB marschaller, I have got a problem:

class A does not have a no-arg default constructor

I used a Java Decomplier to check the class a implementation, it is like this:

public final class AImpl
  implements A

That means I can not extends class AImpl.

So How can I fix the problem with no-arg default constructor?

like image 523
olidev Avatar asked May 30 '11 09:05

olidev


2 Answers

You can use XmlAdapter for this use case. For an example see:

  • http://bdoughan.blogspot.com/2010/12/jaxb-and-immutable-objects.html
  • http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html
like image 106
bdoughan Avatar answered Oct 05 '22 00:10

bdoughan


How do you know values that should be passed to that constructor then?

I think you will need to override Binder class to unmarshall objects by yourself.

like image 44
artplastika Avatar answered Oct 05 '22 01:10

artplastika