가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Prepare Interview

JAXB 면접 질문과 답변

Ques 11. Java code for marshalling Java objects into XML.

• Example
Marshaller m = factory.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer fw = new FileWriter("newCars.xml");
m.marshal(cars, fw);
• marshal method accepts
– java.io.OutputStream
– java.io.Writer
– javax.xml.transform.Result
• related to XSLT
– org.w3c.dom.Node
• related to DOM
– org.xml.sax.ContentHandler
• related to SAX

• Other Marshaller methods
– boolean setEventHandler(ValidationEventHandler handler)
• same as use with Unmarshaller, but validation events
are delivered during marshalling
– void setProperty(String name, Object value)
• supported properties are
– jaxb.encoding - value is a String
» the encoding to use when marshalling; defaults to “UTF-8”
– jaxb.formatted.output - value is a Boolean
» true to output line breaks and indentation; false to omit (the default)
– jaxb.schemaLocation - value is a String
» to specify xsi:schemaLocation attribute in generated XML
– jaxb.noNamespaceSchemaLocation - value is a String
» to specify xsi:noNamespaceSchemaLocation attribute in generated XML

도움이 되었나요? Add Comment View Comments
 

Ques 12. Java example/java program to set object for generating XML.

Cars cars = factory.createCars();
Car car = factory.createCar();
car.setColor("blue");
car.setMake("Mazda");
car.setModel("Miata");
car.setYear(BigInteger.valueOf(2012));
cars.getCar().add(car);
car = factory.createCar();
car.setColor("red");
car.setMake("Ford");
car.setModel("Mustang II");
car.setYear(BigInteger.valueOf(2011));
cars.getCar().add(car);

도움이 되었나요? Add Comment View Comments
 

Ques 13. How to validate java objects?

• The graph of Java objects can contain invalid data
– could occur when objects created by unmarshalling are modified
– could occur when objects are created from scratch
• Use a Validator to validate the objects
• Example
Validator v = factory.createValidator();
try {
v.validateRoot(cars);
v.validate(car);
} catch (ValidationException e) {
// Handle the validation error described by e.getMessage().
}

• Other Validator methods
– boolean setEventHandler(ValidationEventHandler handler)
• handleEvent method of ValidationEventHandler is called
if validation errors are encountered
• default handler terminates marshalling after first error
• return true to continue validating
• return false to terminate with ValidationException

Pass an instance of javax.xml.bind.util.ValidationEventCollector
(in jaxb-api.jar) to setEventHandler to collect validation errors and
query them later instead of handling them during validation.
ValidationEventCollector vec =
new ValidationEventCollector();
v.setEventHandler(vec);
v.validate(cars);
ValidationEvent[] events = vec.getEvents();

도움이 되었나요? Add Comment View Comments
 

Ques 14. Customizing Type Bindings.

• Default bindings can be overridden
– at global scope
– on case-by-case basis
• Customizations include
– names of generated package, classes and methods
– method return types
– class property (field) types
– which elements are bound to classes, as opposed to being ignored
– class property to which each attribute and element declaration is bound

도움이 되었나요? Add Comment View Comments
 

Ques 15. Syntax of customization.

• Customizations can be specified in
– the XML Schema (our focus)
– a binding declarations XML document (not well supported by RI yet)
• The XML Schema must declare
the JAXB namespace and version
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema”
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
• Customization elements are placed in annotation elements
<xsd:annotation>
<xsd:appinfo>
binding declarations
</xsd:appinfo>
</xsd:annotation>

도움이 되었나요? Add Comment View Comments
 

Most helpful rated by users:

Copyright © 2026, WithoutBook.