= JaxbUtils
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Utilities to convert from and to JAXB-XML format.

== API

[source,java]
.JaxbUtils.java
----
class JaxbUtils {
  DtoMapper<T> mapperFor(Class<T> mappedType, JaxbUtils.JaxbCustomizer... customizers)
  Try<T> tryRead(Class<T> mappedType, String stringUtf8, JaxbUtils.JaxbCustomizer... customizers)     // <.>
  Try<T> tryRead(Class<T> mappedType, DataSource source, JaxbUtils.JaxbCustomizer... customizers)     // <.>
  void write(T pojo, DataSink sink, JaxbUtils.JaxbCustomizer... customizers)     // <.>
  String toStringUtf8(T pojo, JaxbUtils.JaxbCustomizer... customizers)     // <.>
  void generateSchema(JAXBContext jaxbContext, DataSink dataSink)     // <.>
  JAXBContext jaxbContextFor(Class<?> primaryClass, Class<?>... additionalClassesToBeBound)     // <.>
  JAXBContext jaxbContextFor(Class<?> dtoClass, boolean useCache)
}
----

<.> xref:#tryRead_Class_String_JaxbUtils_JaxbCustomizer[tryRead(Class, String, JaxbUtils_JaxbCustomizer)]
+
--
Tries to deserialize JAXB-XML content from given UTF8 encoded _String_ into an instance of given _mappedType_ .
--
<.> xref:#tryRead_Class_DataSource_JaxbUtils_JaxbCustomizer[tryRead(Class, DataSource, JaxbUtils_JaxbCustomizer)]
+
--
Tries to deserialize JAXB-XML content from given xref:refguide:commons:index/io/DataSource.adoc[DataSource] into an instance of given _mappedType_ .
--
<.> xref:#write_T_DataSink_JaxbUtils_JaxbCustomizer[write(T, DataSink, JaxbUtils_JaxbCustomizer)]
+
--
Writes given _pojo_ to given xref:refguide:commons:index/io/DataSink.adoc[DataSink] .
--
<.> xref:#toStringUtf8_T_JaxbUtils_JaxbCustomizer[toStringUtf8(T, JaxbUtils_JaxbCustomizer)]
+
--
Converts given _pojo_ to an UTF8 encoded _String_ .
--
<.> xref:#generateSchema_JAXBContext_DataSink[generateSchema(JAXBContext, DataSink)]
+
--
Generates the schema documents for given _JAXBContext_ and writes them to given xref:refguide:commons:index/io/DataSink.adoc[DataSink] .
--
<.> xref:#jaxbContextFor_Class_Class[jaxbContextFor(Class, Class)]
+
--
not cached
--

== Members

[#tryRead_Class_String_JaxbUtils_JaxbCustomizer]
=== tryRead(Class, String, JaxbUtils_JaxbCustomizer)

Tries to deserialize JAXB-XML content from given UTF8 encoded _String_ into an instance of given _mappedType_ .

[#tryRead_Class_DataSource_JaxbUtils_JaxbCustomizer]
=== tryRead(Class, DataSource, JaxbUtils_JaxbCustomizer)

Tries to deserialize JAXB-XML content from given xref:refguide:commons:index/io/DataSource.adoc[DataSource] into an instance of given _mappedType_ .

[#write_T_DataSink_JaxbUtils_JaxbCustomizer]
=== write(T, DataSink, JaxbUtils_JaxbCustomizer)

Writes given _pojo_ to given xref:refguide:commons:index/io/DataSink.adoc[DataSink] .

[#toStringUtf8_T_JaxbUtils_JaxbCustomizer]
=== toStringUtf8(T, JaxbUtils_JaxbCustomizer)

Converts given _pojo_ to an UTF8 encoded _String_ .

[#generateSchema_JAXBContext_DataSink]
=== generateSchema(JAXBContext, DataSink)

Generates the schema documents for given _JAXBContext_ and writes them to given xref:refguide:commons:index/io/DataSink.adoc[DataSink] .

[#jaxbContextFor_Class_Class]
=== jaxbContextFor(Class, Class)

not cached
