001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model.dataformat;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023import javax.xml.bind.annotation.XmlTransient;
024
025import org.apache.camel.model.DataFormatDefinition;
026import org.apache.camel.spi.Metadata;
027
028/**
029 * JacksonXML data format is used for unmarshal a XML payload to POJO or to
030 * marshal POJO back to XML payload.
031 */
032@Metadata(firstVersion = "2.16.0", label = "dataformat,transformation,xml", title = "JacksonXML")
033@XmlRootElement(name = "jacksonxml")
034@XmlAccessorType(XmlAccessType.FIELD)
035public class JacksonXMLDataFormat extends DataFormatDefinition {
036    @XmlAttribute
037    private String xmlMapper;
038    @XmlAttribute
039    private Boolean prettyPrint;
040    @XmlAttribute
041    private String unmarshalTypeName;
042    @XmlTransient
043    private Class<?> unmarshalType;
044    @XmlAttribute
045    private Class<?> jsonView;
046    @XmlAttribute
047    private String include;
048    @XmlAttribute
049    private Boolean allowJmsType;
050    @XmlAttribute
051    private String collectionTypeName;
052    @XmlTransient
053    private Class<?> collectionType;
054    @XmlAttribute
055    private Boolean useList;
056    @XmlAttribute
057    private Boolean enableJaxbAnnotationModule;
058    @XmlAttribute
059    private String moduleClassNames;
060    @XmlAttribute
061    private String moduleRefs;
062    @XmlAttribute
063    private String enableFeatures;
064    @XmlAttribute
065    private String disableFeatures;
066    @XmlAttribute
067    private Boolean allowUnmarshallType;
068
069    public JacksonXMLDataFormat() {
070        super("jacksonxml");
071    }
072
073    public String getXmlMapper() {
074        return xmlMapper;
075    }
076
077    /**
078     * Lookup and use the existing XmlMapper with the given id.
079     */
080    public void setXmlMapper(String xmlMapper) {
081        this.xmlMapper = xmlMapper;
082    }
083
084    public Boolean getPrettyPrint() {
085        return prettyPrint;
086    }
087
088    /**
089     * To enable pretty printing output nicely formatted.
090     * <p/>
091     * Is by default false.
092     */
093    public void setPrettyPrint(Boolean prettyPrint) {
094        this.prettyPrint = prettyPrint;
095    }
096
097    public String getUnmarshalTypeName() {
098        return unmarshalTypeName;
099    }
100
101    /**
102     * Class name of the java type to use when unarmshalling
103     */
104    public void setUnmarshalTypeName(String unmarshalTypeName) {
105        this.unmarshalTypeName = unmarshalTypeName;
106    }
107
108    public Class<?> getUnmarshalType() {
109        return unmarshalType;
110    }
111
112    /**
113     * Class of the java type to use when unarmshalling
114     */
115    public void setUnmarshalType(Class<?> unmarshalType) {
116        this.unmarshalType = unmarshalType;
117    }
118
119    public Class<?> getJsonView() {
120        return jsonView;
121    }
122
123    /**
124     * When marshalling a POJO to JSON you might want to exclude certain fields
125     * from the JSON output. With Jackson you can use JSON views to accomplish
126     * this. This option is to refer to the class which has @JsonView
127     * annotations
128     */
129    public void setJsonView(Class<?> jsonView) {
130        this.jsonView = jsonView;
131    }
132
133    public String getInclude() {
134        return include;
135    }
136
137    /**
138     * If you want to marshal a pojo to JSON, and the pojo has some fields with
139     * null values. And you want to skip these null values, you can set this
140     * option to <tt>NON_NULL</tt>
141     */
142    public void setInclude(String include) {
143        this.include = include;
144    }
145
146    public Boolean getAllowJmsType() {
147        return allowJmsType;
148    }
149
150    /**
151     * Used for JMS users to allow the JMSType header from the JMS spec to
152     * specify a FQN classname to use to unmarshal to.
153     */
154    public void setAllowJmsType(Boolean allowJmsType) {
155        this.allowJmsType = allowJmsType;
156    }
157
158    public String getCollectionTypeName() {
159        return collectionTypeName;
160    }
161
162    /**
163     * Refers to a custom collection type to lookup in the registry to use. This
164     * option should rarely be used, but allows to use different collection
165     * types than java.util.Collection based as default.
166     */
167    public void setCollectionTypeName(String collectionTypeName) {
168        this.collectionTypeName = collectionTypeName;
169    }
170
171    public Class<?> getCollectionType() {
172        return collectionType;
173    }
174
175    public void setCollectionType(Class<?> collectionType) {
176        this.collectionType = collectionType;
177    }
178
179    public Boolean getUseList() {
180        return useList;
181    }
182
183    /**
184     * To unarmshal to a List of Map or a List of Pojo.
185     */
186    public void setUseList(Boolean useList) {
187        this.useList = useList;
188    }
189
190    public Boolean getEnableJaxbAnnotationModule() {
191        return enableJaxbAnnotationModule;
192    }
193
194    /**
195     * Whether to enable the JAXB annotations module when using jackson. When
196     * enabled then JAXB annotations can be used by Jackson.
197     */
198    public void setEnableJaxbAnnotationModule(Boolean enableJaxbAnnotationModule) {
199        this.enableJaxbAnnotationModule = enableJaxbAnnotationModule;
200    }
201
202    public String getModuleClassNames() {
203        return moduleClassNames;
204    }
205
206    /**
207     * To use custom Jackson modules com.fasterxml.jackson.databind.Module
208     * specified as a String with FQN class names. Multiple classes can be
209     * separated by comma.
210     */
211    public void setModuleClassNames(String moduleClassNames) {
212        this.moduleClassNames = moduleClassNames;
213    }
214
215    public String getModuleRefs() {
216        return moduleRefs;
217    }
218
219    /**
220     * To use custom Jackson modules referred from the Camel registry. Multiple
221     * modules can be separated by comma.
222     */
223    public void setModuleRefs(String moduleRefs) {
224        this.moduleRefs = moduleRefs;
225    }
226
227    public String getEnableFeatures() {
228        return enableFeatures;
229    }
230
231    /**
232     * Set of features to enable on the Jackson
233     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
234     * <p/>
235     * The features should be a name that matches a enum from
236     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
237     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
238     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
239     * <p/>
240     * Multiple features can be separated by comma
241     */
242    public void setEnableFeatures(String enableFeatures) {
243        this.enableFeatures = enableFeatures;
244    }
245
246    public String getDisableFeatures() {
247        return disableFeatures;
248    }
249
250    /**
251     * Set of features to disable on the Jackson
252     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
253     * <p/>
254     * The features should be a name that matches a enum from
255     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
256     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
257     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
258     * <p/>
259     * Multiple features can be separated by comma
260     */
261    public void setDisableFeatures(String disableFeatures) {
262        this.disableFeatures = disableFeatures;
263    }
264
265    public Boolean getAllowUnmarshallType() {
266        return allowUnmarshallType;
267    }
268
269    /**
270     * If enabled then Jackson is allowed to attempt to use the
271     * CamelJacksonUnmarshalType header during the unmarshalling.
272     * <p/>
273     * This should only be enabled when desired to be used.
274     */
275    public void setAllowUnmarshallType(Boolean allowUnmarshallType) {
276        this.allowUnmarshallType = allowUnmarshallType;
277    }
278
279    @Override
280    public String getDataFormatName() {
281        return "jacksonxml";
282    }
283
284}