In my XML I have
<myelem required="false"/>
How I can read the required attribute as a boolean? I can read it as String and inside a getter do this: return new Boolean(required)
But maybe there are some more elegant ways?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just simply use
booleanfor the member in your Java class:Or, if you use getter-setter style of mapping:
The JAXB unmarshaller is able to interpret
"true"and"false"strings in the XML document asbooleanvalue.UPDATE:
I tested this with the following classes:
test/MyElem.java:
Test.java:
And with the following input (test.xml):
I get the correct result on the console: