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?
Asked
Active
Viewed 39 times
1 Answers
1
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
.

bdoughan
- 147,609
- 23
- 300
- 400
-
Before reading your answer, I actually found an answer in the MOXy documentation [here](http://eclipse.org/eclipselink/documentation/2.5/moxy/advanced_concepts006.htm). Did you write it? – Michael Dec 15 '14 at 10:08