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 CBOR payload to POJO and back.
030 */
031@Metadata(firstVersion = "3.0.0", label = "dataformat,transformation,json", title = "CBOR")
032@XmlRootElement(name = "cbor")
033@XmlAccessorType(XmlAccessType.FIELD)
034public class CBORDataFormat extends DataFormatDefinition {
035    @XmlAttribute
036    private String objectMapper;
037    @XmlAttribute
038    @Metadata(defaultValue = "true", javaType = "java.lang.Boolean")
039    private String useDefaultObjectMapper;
040    @XmlAttribute
041    private String unmarshalTypeName;
042    @XmlTransient
043    private Class<?> unmarshalType;
044    @XmlAttribute
045    private String collectionTypeName;
046    @XmlTransient
047    private Class<?> collectionType;
048    @XmlAttribute
049    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
050    private String useList;
051    @XmlAttribute
052    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
053    private String allowUnmarshallType;
054    @XmlAttribute
055    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
056    private String prettyPrint;
057    @XmlAttribute
058    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
059    private String allowJmsType;
060    @XmlAttribute
061    private String enableFeatures;
062    @XmlAttribute
063    private String disableFeatures;
064
065    public CBORDataFormat() {
066        super("cbor");
067    }
068
069    public String getObjectMapper() {
070        return objectMapper;
071    }
072
073    /**
074     * Lookup and use the existing CBOR ObjectMapper with the given id when
075     * using Jackson.
076     */
077    public void setObjectMapper(String objectMapper) {
078        this.objectMapper = objectMapper;
079    }
080
081    public String getUseDefaultObjectMapper() {
082        return useDefaultObjectMapper;
083    }
084
085    /**
086     * Whether to lookup and use default Jackson CBOR ObjectMapper from the
087     * registry.
088     */
089    public void setUseDefaultObjectMapper(String useDefaultObjectMapper) {
090        this.useDefaultObjectMapper = useDefaultObjectMapper;
091    }
092
093    public String getUnmarshalTypeName() {
094        return unmarshalTypeName;
095    }
096
097    /**
098     * Class name of the java type to use when unmarshalling
099     */
100    public void setUnmarshalTypeName(String unmarshalTypeName) {
101        this.unmarshalTypeName = unmarshalTypeName;
102    }
103
104    public Class<?> getUnmarshalType() {
105        return unmarshalType;
106    }
107
108    public String getPrettyPrint() {
109        return prettyPrint;
110    }
111
112    /**
113     * To enable pretty printing output nicely formatted.
114     * <p/>
115     * Is by default false.
116     */
117    public void setPrettyPrint(String prettyPrint) {
118        this.prettyPrint = prettyPrint;
119    }
120
121    public String getAllowJmsType() {
122        return allowJmsType;
123    }
124
125    /**
126     * Used for JMS users to allow the JMSType header from the JMS spec to
127     * specify a FQN classname to use to unmarshal to.
128     */
129    public void setAllowJmsType(String allowJmsType) {
130        this.allowJmsType = allowJmsType;
131    }
132
133    /**
134     * Class of the java type to use when unmarshalling
135     */
136    public void setUnmarshalType(Class<?> unmarshalType) {
137        this.unmarshalType = unmarshalType;
138    }
139
140    public String getCollectionTypeName() {
141        return collectionTypeName;
142    }
143
144    /**
145     * Refers to a custom collection type to lookup in the registry to use. This
146     * option should rarely be used, but allows to use different collection
147     * types than java.util.Collection based as default.
148     */
149    public void setCollectionTypeName(String collectionTypeName) {
150        this.collectionTypeName = collectionTypeName;
151    }
152
153    public Class<?> getCollectionType() {
154        return collectionType;
155    }
156
157    public void setCollectionType(Class<?> collectionType) {
158        this.collectionType = collectionType;
159    }
160
161    public String getUseList() {
162        return useList;
163    }
164
165    /**
166     * To unmarshal to a List of Map or a List of Pojo.
167     */
168    public void setUseList(String useList) {
169        this.useList = useList;
170    }
171
172    public String getAllowUnmarshallType() {
173        return allowUnmarshallType;
174    }
175
176    /**
177     * If enabled then Jackson CBOR is allowed to attempt to use the
178     * CamelCBORUnmarshalType header during the unmarshalling.
179     * <p/>
180     * This should only be enabled when desired to be used.
181     */
182    public void setAllowUnmarshallType(String allowUnmarshallType) {
183        this.allowUnmarshallType = allowUnmarshallType;
184    }
185
186    public String getEnableFeatures() {
187        return enableFeatures;
188    }
189
190    /**
191     * Set of features to enable on the Jackson
192     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
193     * <p/>
194     * The features should be a name that matches a enum from
195     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
196     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
197     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
198     * <p/>
199     * Multiple features can be separated by comma
200     */
201    public void setEnableFeatures(String enableFeatures) {
202        this.enableFeatures = enableFeatures;
203    }
204
205    public String getDisableFeatures() {
206        return disableFeatures;
207    }
208
209    /**
210     * Set of features to disable on the Jackson
211     * <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
212     * <p/>
213     * The features should be a name that matches a enum from
214     * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
215     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or
216     * <tt>com.fasterxml.jackson.databind.MapperFeature</tt>
217     * <p/>
218     * Multiple features can be separated by comma
219     */
220    public void setDisableFeatures(String disableFeatures) {
221        this.disableFeatures = disableFeatures;
222    }
223
224}