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 * Unmarshal a XML payloads to POJOs and back using XMLMapper extension of Jackson.
030 */
031@Metadata(firstVersion = "2.16.0", label = "dataformat,transformation,xml", title = "JacksonXML")
032@XmlRootElement(name = "jacksonxml")
033@XmlAccessorType(XmlAccessType.FIELD)
034public class JacksonXMLDataFormat extends DataFormatDefinition {
035    @XmlAttribute
036    private String xmlMapper;
037    @XmlAttribute
038    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
039    private String 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    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
050    private String allowJmsType;
051    @XmlAttribute
052    private String collectionTypeName;
053    @XmlTransient
054    private Class<?> collectionType;
055    @XmlAttribute
056    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
057    private String useList;
058    @XmlAttribute
059    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
060    private String enableJaxbAnnotationModule;
061    @XmlAttribute
062    private String moduleClassNames;
063    @XmlAttribute
064    private String moduleRefs;
065    @XmlAttribute
066    private String enableFeatures;
067    @XmlAttribute
068    private String disableFeatures;
069    @XmlAttribute
070    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
071    private String allowUnmarshallType;
072
073    public JacksonXMLDataFormat() {
074        super("jacksonxml");
075    }
076
077    public String getXmlMapper() {
078        return xmlMapper;
079    }
080
081    /**
082     * Lookup and use the existing XmlMapper with the given id.
083     */
084    public void setXmlMapper(String xmlMapper) {
085        this.xmlMapper = xmlMapper;
086    }
087
088    public String getPrettyPrint() {
089        return prettyPrint;
090    }
091
092    /**
093     * To enable pretty printing output nicely formatted.
094     * <p/>
095     * Is by default false.
096     */
097    public void setPrettyPrint(String prettyPrint) {
098        this.prettyPrint = prettyPrint;
099    }
100
101    public String getUnmarshalTypeName() {
102        return unmarshalTypeName;
103    }
104
105    /**
106     * Class name of the java type to use when unmarshalling
107     */
108    public void setUnmarshalTypeName(String unmarshalTypeName) {
109        this.unmarshalTypeName = unmarshalTypeName;
110    }
111
112    public Class<?> getUnmarshalType() {
113        return unmarshalType;
114    }
115
116    /**
117     * Class of the java type to use when unmarshalling
118     */
119    public void setUnmarshalType(Class<?> unmarshalType) {
120        this.unmarshalType = unmarshalType;
121    }
122
123    public Class<?> getJsonView() {
124        return jsonView;
125    }
126
127    /**
128     * When marshalling a POJO to JSON you might want to exclude certain fields
129     * from the JSON output. With Jackson you can use JSON views to accomplish
130     * this. This option is to refer to the class which has @JsonView
131     * annotations
132     */
133    public void setJsonView(Class<?> jsonView) {
134        this.jsonView = jsonView;
135    }
136
137    public String getInclude() {
138        return include;
139    }
140
141    /**
142     * If you want to marshal a pojo to JSON, and the pojo has some fields with
143     * null values. And you want to skip these null values, you can set this
144     * option to <tt>NON_NULL</tt>
145     */
146    public void setInclude(String include) {
147        this.include = include;
148    }
149
150    public String getAllowJmsType() {
151        return allowJmsType;
152    }
153
154    /**
155     * Used for JMS users to allow the JMSType header from the JMS spec to
156     * specify a FQN classname to use to unmarshal to.
157     */
158    public void setAllowJmsType(String allowJmsType) {
159        this.allowJmsType = allowJmsType;
160    }
161
162    public String getCollectionTypeName() {
163        return collectionTypeName;
164    }
165
166    /**
167     * Refers to a custom collection type to lookup in the registry to use. This
168     * option should rarely be used, but allows to use different collection
169     * types than java.util.Collection based as default.
170     */
171    public void setCollectionTypeName(String collectionTypeName) {
172        this.collectionTypeName = collectionTypeName;
173    }
174
175    public Class<?> getCollectionType() {
176        return collectionType;
177    }
178
179    public void setCollectionType(Class<?> collectionType) {
180        this.collectionType = collectionType;
181    }
182
183    public String getUseList() {
184        return useList;
185    }
186
187    /**
188     * To unmarshal to a List of Map or a List of Pojo.
189     */
190    public void setUseList(String useList) {
191        this.useList = useList;
192    }
193
194    public String getEnableJaxbAnnotationModule() {
195        return enableJaxbAnnotationModule;
196    }
197
198    /**
199     * Whether to enable the JAXB annotations module when using jackson. When
200     * enabled then JAXB annotations can be used by Jackson.
201     */
202    public void setEnableJaxbAnnotationModule(String enableJaxbAnnotationModule) {
203        this.enableJaxbAnnotationModule = enableJaxbAnnotationModule;
204    }
205
206    public String getModuleClassNames() {
207        return moduleClassNames;
208    }
209
210    /**
211     * To use custom Jackson modules com.fasterxml.jackson.databind.Module
212     * specified as a String with FQN class names. Multiple classes can be
213     * separated by comma.
214     */
215    public void setModuleClassNames(String moduleClassNames) {
216        this.moduleClassNames = moduleClassNames;
217    }
218
219    public String getModuleRefs() {
220        return moduleRefs;
221    }
222
223    /**
224     * To use custom Jackson modules referred from the Camel registry. Multiple
225     * modules can be separated by comma.
226     */
227    public void setModuleRefs(String moduleRefs) {
228        this.moduleRefs = moduleRefs;
229    }
230
231    public String getEnableFeatures() {
232        return enableFeatures;
233    }
234
235    /**
236     * Set of features to enable on the Jackson
237     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
238     * <p/>
239     * The features should be a name that matches a enum from
240     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
241     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
242     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
243     * <p/>
244     * Multiple features can be separated by comma
245     */
246    public void setEnableFeatures(String enableFeatures) {
247        this.enableFeatures = enableFeatures;
248    }
249
250    public String getDisableFeatures() {
251        return disableFeatures;
252    }
253
254    /**
255     * Set of features to disable on the Jackson
256     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
257     * <p/>
258     * The features should be a name that matches a enum from
259     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
260     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
261     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
262     * <p/>
263     * Multiple features can be separated by comma
264     */
265    public void setDisableFeatures(String disableFeatures) {
266        this.disableFeatures = disableFeatures;
267    }
268
269    public String getAllowUnmarshallType() {
270        return allowUnmarshallType;
271    }
272
273    /**
274     * If enabled then Jackson is allowed to attempt to use the
275     * CamelJacksonUnmarshalType header during the unmarshalling.
276     * <p/>
277     * This should only be enabled when desired to be used.
278     */
279    public void setAllowUnmarshallType(String allowUnmarshallType) {
280        this.allowUnmarshallType = allowUnmarshallType;
281    }
282
283}