JAXB is the standard Java API which bridges the gap between XML and Java objects. This course will teach you how to use JAXB, different approaches for working with XML schemas, integrating JAXB in your build process and using JAXB with webservices.
As a software developer, it's important to have a thorough knowledge of how to work with XML, the well-known standard data format that is used in all kinds of applications. In this course, Working with XML in Java Using JAXB, you will learn how to use the Java Architecture for XML Binding (JAXB) effectively. First, you will learn about how to use the JAXB API to convert XML to Java objects and vice versa. Next, you'll explore how to work with XML schemas. Finally, you'll dive into using JAXB for working with web services. When you're finished with this course, you'll have a foundational knowledge of JAXB that will help you as you move forward to become an expert Java developer.
Jesper de Jong is an independent, experienced software developer and architect who designs and builds efficient, scalable, and high-quality server-side software for the JVM in Java and Scala. He loves the creativity of inventing and building software systems and loves to teach and share his knowledge with the software development community.
Course Overview Hi everyone. My name is Jesper de Jong, and welcome to my course, Working with XML in Java Using JAXB. I'm an independent software developer, and I have a lot of experience with designing and building enterprise software systems in Java. XML is a very widely used data format, and as a Java developer, you'll definitely need to know how to work with XML in Java. Java has extensive support for working with XML and JAXB. The Java architecture for XML binding is Java standard high-level API, which bridges the gap between XML and the object-oriented Java world. This course is for all Java developers who want to expand their knowledge of working with XML in Java. Some of the major topics that we'll cover include converting XML to Java objects and vice versa, using JAXB annotations and bindings files, the code-first and the schema-first approach to working with JAXB, integrating JAXB into your build process, and using JAXB for JAX-WS webservices. By the end of this course, you'll have a solid understanding of how to work with XML using JAXB and the underlying concepts. Before beginning the course, you should be familiar with the Java programming language and have a basic understanding of XML. I hope you'll join me on this journey to learn JAXB with the Working with XML in Java Using JAXB course, at Pluralsight.
Introduction to JAXB Hello, and welcome to the course, Working with XML in Java Using JAXB. My name is Jesper de Jong. XML is a standard and widely used data format. It's used to exchange and store information in many different applications from web services to configuration files and for many other purposes. Since it's used for so many different applications, as a software developer, you will undoubtedly need to work with XML in many of your projects. This course is about JAXB, the Java architecture for XML binding. JAXB is one of several different standard Java APIs for working with XML. In this introduction module, you'll get a high-level idea of what JAXB is and where it fits in the bigger picture. We'll have a look at where this course fits in the Pluralsight course curriculum, and you'll get an overview of what subjects you'll learn in this course. Finally, I assume that you're already familiar with the basic concepts of XML and XML schema, but to refresh your knowledge, I'll give you a quick overview of the most important concepts of XML and XSD at the end of this module so that you're all set to dive into JAXB.
Reading and Writing XML with JAXB Welcome again to this course about the Java architecture for XML binding. In this module, you'll learn the basics of the JAXB API. We'll start with a quick overview of the most important concepts and terminology of the JAXB API, and then we're going to work with it hands-on. We'll first take a look at how to convert Java objects to XML and then at how to read XML and convert it back to Java objects. As you'll see, the basics are not very complicated, and you'll only need a few lines of code. The goal here is to get you started quickly with using the API and setting a foundation for the coming modules. Let's get started.
Generating Java Classes from an XML Schema In the previous modules, you've learned a lot about the code-first approach. You know how to define a domain model in Java and annotate it with JAXB annotations, and how to generate a schema from the Java domain model. In this module, we are going to learn about the schema-first approach. First, we will compare the schema-first approach to the code-first approach and think about what the pros and cons of each approach are so that you understand when you might want to choose one or the other. Then you'll learn to work with the schema-first approach in practice by using the xjc tool to generate Java classes from an XSD. Next, we'll take a look at how using the generated classes differs from using the handwritten Java domain model classes by looking at how to use the generated classes for marshalling. Just like how you can customize how classes, fields, and properties are mapped to XML by using the JAXB annotations in the code-first approach, it's possible to extensively customize how types, elements, and attributes in an XSD are mapped to Java classes in the schema-first approach. The rest of this module will be about these customizations. First, you'll learn about the basics of how to customize mappings, and you'll see a number of possible things you can do. Then, we'll look at an interesting example, which is how you can tell JAXB to make use of the new Java 8 date and time classes. And finally, you'll learn how you can customize the mapping of enum types. Let's get started and see what the schema-first approach is all about.
Integrating the JAXB Tools into Your Build Process In all the examples until now, we've been using the JDK JAXB tools by simply running them directly in a terminal window. When you're using a build tool such as Maven or Gradle for your project, then you'll want to have your build tool run the JAXB tools for you at the appropriate moment in the build process. In this module, you'll learn how you can use schemagen and xjc in Maven and Gradle projects. We'll start with running schemagen to generate an XSD from Java classes in a Maven project. Then we'll take a look at running xjc in a Maven project. We'll use xjc to generate Java domain model classes from an XSD and then let Maven compile the generated sources together with our own source files. After the two Maven examples, we'll look at two similar examples using Gradle, first an example of how to use schemagen, and then an example of how to use xjc in a Gradle project. Let's start with the Maven examples.
Using JAXB with JAX-WS Web Services Welcome to the last module of this course. You've now learned a lot about JAXB. JAXB is useful for many different applications, and one application where it is often used is XML-based web services. In this module, we'll create a simple web service and the client so that you get an idea of how JAXB is used for web services. First, I'll give you some background information about web services so that you understand the context. Then we'll look at two examples. First, we'll create a simple web service for purchase orders using JAX-WS, the standard Java API for working with XML-based web services and JAXB. Then we'll create a small client program which calls the web service. Let's start with a quick overview of web services.