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