Shervin Asgari
Shervin Asgari

Reputation: 24509

JAXB together with Builder Pattern. Is that possible?

I was wondering if anybody knows how I can use JAXB together with the Builder Pattern? The builder pattern wants you to set the constructor as private, and JAXB says

"1 counts of IllegalAnnotationExceptions myClass does not have a no-arg default constructor"

Is there somehow I can tell JAXB that I don't want no-arg default constructor, and that it can create a new instance using the Builder pattern somehow?

Update I should note (even though it shouldn't be relevant) that I am using Axis 2 to generate my stub files.

Upvotes: 1

Views: 1910

Answers (2)

user301825
user301825

Reputation:

jaxb provides an ObjectFactory when you generate the classes from the schema with xjc.bat

Upvotes: 0

Mike Thomsen
Mike Thomsen

Reputation: 37526

I don't know the specifics of how to do it, as I've never had to do it, but you can tell JAXB to use a factory class to generate objects. I did a quick google search on it and there appears to be some of the data you're looking for right off the bat.

Upvotes: 1

Related Questions