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