Рет қаралды 32,651
Generating Java JAXB classes from an XSD schema is a common task. In this tutorial I show you how to use the maven-jaxb2-plugin to generate the JAXB java classes. (From group org.jvnet.jaxb2.maven2).
By the way - have you tried MOXy? I actually find it more maintainable than handing JAXB objects; but thats another video topic!.
I additionally show you how to use Spring Framework OXM Jaxb2Marshaller to marshal JAXB java objects into XML and unmarshal XML into JAXB java objects.
00:00 - 01:23 Tutorial Introduction from a beach in Andalusia; Spain. During my morning walk.
01:23 - 01:46 Create Spring Starter Project
01:46 - 02:40 Created XML XSD Schema
02:40 - 03:50 Added maven-jaxb2-plugin to the applications POM
03:50 - 04:40 Generated the JAXB Java Objects representing the schema
04:40 - 04:52 Added Spring Framework OXM dependency to the POM
04:52 - 08:55 Created Spring Jaxb2Marshaller with context path, schema resource validation and pretty print property.
08:55 - 10:33 Created JAXB Java Objects to perform marshalling on
10:33 - 12:30 Marshalled JAXB Java Object into XML with Jaxb2Marshaller StreamResult and StringWriter. Could also use StringResult.
12:30 - 13:00 Fixed the exception thrown by adding the missing context path and schema properties.
13:00 - 14:45 Unmarshalled XML into JAXB java objects using Jaxb2Marshaller StreamSource and StringReader.
14:45 - 15:50 Maven & Spring JAXB Integration example summary
I hope you learned something new and enjoyed the video; subscribe for more regular tech videos!
Enjoy! :)
Philip
JAXB2 Maven Plugin: github.com/highsource/maven-jaxb2-plugin
JAXB2 Maven Plugin Configuration Cheat Sheet: github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet
Alexey Valikov Highsource: github.com/highsource
Spring Framework Marshalling XML using O/X Mappers: docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html
Jaxb2Marshaller: docs.spring.io/spring/docs/current/javadoc-api/org/springframework/oxm/jaxb/Jaxb2Marshaller.html
Spring Initializr: start.spring.io/
MOXy EclipseLink for the interested: wiki.eclipse.org/EclipseLink/Examples/MOXy