1Z0-900 · Question #11
Given the code fragment: Which method should be used on line 3 to enable default validation mechanism?
The correct answer is D. u.setAdapter(XmlAdapter). Note: This question appears to have a potentially incorrect answer key. Based on standard JAXB (javax.xml.bind) APIs, setAdapter(XmlAdapter) is used for custom type binding/conversion, not for enabling validation. The method that actually enables default XML validation in JAXB…
Question
Given the code fragment:
Which method should be used on line 3 to enable default validation mechanism?
Options
- Au.setProperty(String, Object)
- Bu.setProperty(Schema)
- Cu.setEventHandler(ValidationEventHandler)
- Du.setAdapter(XmlAdapter)
How the community answered
(42 responses)- A7% (3)
- C5% (2)
- D88% (37)
Explanation
Note: This question appears to have a potentially incorrect answer key. Based on standard JAXB (javax.xml.bind) APIs, setAdapter(XmlAdapter) is used for custom type binding/conversion, not for enabling validation. The method that actually enables default XML validation in JAXB is setSchema(Schema) on the Unmarshaller - closest to option B, though B's signature is wrong (setProperty(Schema) doesn't exist). This looks like a flawed exam question common in some Java certification prep materials.
That said, here's how the options break down:
- A -
setProperty(String, Object)sets implementation-specific properties (likeJAXB_ENCODING), not validation. - B -
setProperty(Schema)doesn't exist as a method; the real validation method issetSchema(Schema), making this a distractor using a plausible-but-wrong signature. - C -
setEventHandler(ValidationEventHandler)installs a listener for validation events but doesn't itself enable validation. - D -
setAdapter(XmlAdapter)registers a custom type adapter for data conversion, unrelated to validation.
For the exam: If your prep material marks D as correct, memorize it as-is. But if you encounter a real JAXB question on production certification exams (OCP), know that unmarshaller.setSchema(schema) is the genuine way to enable schema-based validation.
Topics
Community Discussion
No community discussion yet for this question.