Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Tatu Saloranta edited this pageMay 12, 2023 ·46 revisions

Home: Jackson XML databind Wiki

This is the home page for "jackson-xml-databind" project. The main deliverable of the project is a jar that contains extension toJackson JSON library, to extend it so that it can bind XML to POJOs (and vice versa), instead of using JSON.

Basic usage

Intended usage is by instantiating 'com.fasterxml.jackson.xml.XmlMapper', and using it just like standard Jackson 'ObjectMapper' -- the difference being that instead of JSON, external data format is XML. That is:

importcom.fasterxml.jackson.xml.XmlMapper;// with Jackson 2.10 and laterObjectMappermapper =XmlMapper.builder()// possible configuration changes    .build();// or, with Jackson versions before 2.10 (also exists for later versions)ObjectMappermapper =newXmlMapper();

For most usage that is all there is!

One alternative is that if you need to change some configuration, you may need to first configure module, then construct mapper:

JacksonXmlModulemodule =newJacksonXmlModule();// to default to using "unwrapped" Lists:module.setDefaultUseWrapper(false);XmlMapperxmlMapper =XmlMapper.builder(module)    .build();

Note that underlyingJsonParser andJsonGenerator instances are specific subtypes as well (FromXmlParser,ToXmlGenerator), but usually you don't have to worry about this.

Usage: pretty-printing

Although basic pretty-printing using like this works fine with XML:

Stringdoc =mapper.writerWithDefaultPrettyPrinter().writeValue(value);

you may want to use specifically configured pretty-printer. XML module requires specificPrettyPrinter subtype (XmlPrettyPrinter); used of standard JSON-basedDefaultPrettyPrinter does not work.So when writing XML, you need to pretty print the XML using theDefaultXmlPrettyPrinter.

DefaultXmlPrettyPrinterxmlPrettyPrinter =newDefaultXmlPrettyPrinter();// you can then configure the settings on the xmlPrettyPrinter instancexmlMapper.setDefaultPrettyPrinter(xmlPrettyPrinter);

Licensing

Project is licensed under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) like all official Jackson components.

FasterXML also explicitly allows users to alternatively license component underLesser GPL (LGPL) 2.1 up to and including version 2.2.If so, they may want to repackage artifacts to reflect their choice of license to use.

Documentation

Javadocs

Seejavadoc.io docs andselect the appropriate API version in top banner.

Snapshots

Snapshot builds can be found from Sonatype Maven Snapshot repository:

<snapshotRepository>   <id>sonatype-nexus-snapshots</id>   <name>Sonatype Nexus Snapshots</name>   <url>https://oss.sonatype.org/content/repositories/snapshots</url></snapshotRepository>

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp