Jackson XJC Plugin

A XJC plugin to automate application of Jackson annotations.

Лицензия

Лицензия

Категории

Категории

Jackson Данные JSON
Группа

Группа

io.fares.bind.xjc.plugins
Идентификатор

Идентификатор

jackson-xjc-plugin
Последняя версия

Последняя версия

0.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Jackson XJC Plugin
A XJC plugin to automate application of Jackson annotations.
Ссылка на сайт

Ссылка на сайт

https://github.com/bertramn/jackson-xjc-plugin
Система контроля версий

Система контроля версий

https://github.com/bertramn/jackson-xjc-plugin.git

Скачать jackson-xjc-plugin

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.fares.bind.xjc.plugins/jackson-xjc-plugin/ -->
<dependency>
    <groupId>io.fares.bind.xjc.plugins</groupId>
    <artifactId>jackson-xjc-plugin</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.fares.bind.xjc.plugins/jackson-xjc-plugin/
implementation 'io.fares.bind.xjc.plugins:jackson-xjc-plugin:0.0.2'
// https://jarcasting.com/artifacts/io.fares.bind.xjc.plugins/jackson-xjc-plugin/
implementation ("io.fares.bind.xjc.plugins:jackson-xjc-plugin:0.0.2")
'io.fares.bind.xjc.plugins:jackson-xjc-plugin:jar:0.0.2'
<dependency org="io.fares.bind.xjc.plugins" name="jackson-xjc-plugin" rev="0.0.2">
  <artifact name="jackson-xjc-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.fares.bind.xjc.plugins', module='jackson-xjc-plugin', version='0.0.2')
)
libraryDependencies += "io.fares.bind.xjc.plugins" % "jackson-xjc-plugin" % "0.0.2"
[io.fares.bind.xjc.plugins/jackson-xjc-plugin "0.0.2"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-annotations jar 2.9.8
org.jvnet.jaxb2_commons : jaxb2-basics-tools jar 0.12.0

provided (3)

Идентификатор библиотеки Тип Версия
javax.xml.bind : jaxb-api jar 2.3.1
org.glassfish.jaxb : jaxb-xjc jar 2.3.0
org.glassfish.jaxb : codemodel jar 2.3.0

Модули Проекта

Данный проект не имеет модулей.

Jackson XJC Plugin

This plugin provides tooling to add Jackson annotations to generated Java Beans.

Usage

  1. Configure the XJC compiler

The plugin can be used with any JAXB compiler that is capable of registering XJC plugins. The plugin jar needs to be made available to the XJC compiler classpath. In maven this is not the project classpath but the classpath of the plugin that generates code from one or more XML schema.

Example configuration for the JAXB2 commons compiler:

<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <configuration>
    <plugins>
      <plugin>
        <groupId>io.fares.bind.xjc.plugins</groupId>
        <artifactId>jackson-xjc-plugin</artifactId>
        <version>0.0.2</version>
      </plugin>
    </plugins>
    <extension>true</extension>
    <args>
      <arg>-Xjackson</arg>
    </args>
  </configuration>
</plugin>

Enum Annotations

The plugin will now enhance the enum VehicleType with the Jackson annotations so that the values are serialised/deserialised as defined in the schema, NOT as dictated by Java convention.

@XmlType(name = "VehicleType")
@XmlEnum
public enum VehicleType {

    @XmlEnumValue("Car")
    CAR("Car"),
    @XmlEnumValue("Boat")
    BOAT("Boat"),
    @XmlEnumValue("Plane")
    PLANE("Plane");
    private final String value;

    VehicleType(String v) {
        value = v;
    }

    @JsonValue
    public String value() {
        return value;
    }

    @JsonCreator
    public static VehicleType fromValue(String v) {
        for (VehicleType c: VehicleType.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }

}

Fixed Value Attributes as Constants

When enabling the fixedAttributeAsConstantProperty binding customization, the generated code becomes non-processable by Jackson. When a xsd:attribute is fixed, the plugin will generate a read-only getter method for the attribute so Jackson can serialise the object including this piece of data.

<xsd:schema>
  <xsd:annotation>
    <xsd:appinfo>
      <jaxb:globalBindings fixedAttributeAsConstantProperty="true"/>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:complexType name="SomeType">
    <xsd:attribute name="fixedAttribute" type="xsd:string" fixed="fixed value"/>
  </xsd:complexType>
</xsd:schema>

will generate

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SomeType")
public class SomeType {

    @XmlAttribute(name = "fixedAttribute")
    public final static String FIXED_ATTRIBUTE = "fixed value";

    @XmlTransient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    public String getFixedAttribute() {
        return FIXED_ATTRIBUTE;
    }

}

Версии библиотеки

Версия
0.0.2
0.0.1