Michael
Michael

Reputation: 112

JAXB - adapter for a library object

I want to read an integer (inside XML element) to a Semaphore instead of int, effectively calling Semaphore(int theInteger) . Problem is - Semaphore doesn't have a default constructor. If it was a class I wrote I could either make a no-arg private constructor or write an adapter, but since I have no access to Semaphore - what can I do?

Upvotes: 1

Views: 51

Answers (1)

bdoughan
bdoughan

Reputation: 149047

An object that you are adapting with an XmlAdapter doesn't need to a no-art constructor. You could set it up as follows:

SemaphoreAdapter extends XmlAdapter<Integer, Semaphore>

Then you would use the @XmlJavaTypeAdapter annotation on the property of type Semaphore to reference the XmlAdapter.

Upvotes: 1

Related Questions