Class JsonDataFormat
- java.lang.Object
-
- org.apache.camel.model.IdentifiedType
-
- org.apache.camel.model.DataFormatDefinition
-
- org.apache.camel.model.dataformat.JsonDataFormat
-
- All Implemented Interfaces:
ContentTypeHeaderAware
@Metadata(label="dataformat,transformation,json", title="JSon") public class JsonDataFormat extends DataFormatDefinition implements ContentTypeHeaderAware
Marshal POJOs to JSON and back.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonDataFormat.Builder
Builder
is a specific builder forJsonDataFormat
.
-
Constructor Summary
Constructors Constructor Description JsonDataFormat()
JsonDataFormat(JsonLibrary library)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonDataFormat
allowJmsType(boolean allowJmsType)
JsonDataFormat
allowJmsType(String allowJmsType)
JsonDataFormat
allowUnmarshallType(boolean allowUnmarshallType)
JsonDataFormat
allowUnmarshallType(String allowUnmarshallType)
JsonDataFormat
autoDiscoverObjectMapper(boolean autoDiscoverObjectMapper)
JsonDataFormat
autoDiscoverObjectMapper(String autoDiscoverObjectMapper)
JsonDataFormat
collectionType(Class<?> collectionType)
JsonDataFormat
collectionType(String collectionType)
JsonDataFormat
disableFeatures(String disableFeatures)
JsonDataFormat
dropRootNode(boolean dropRootNode)
JsonDataFormat
dropRootNode(String dropRootNode)
JsonDataFormat
enableFeatures(String enableFeatures)
String
getAllowJmsType()
String
getAllowUnmarshallType()
String
getAutoDiscoverObjectMapper()
String
getAutoDiscoverSchemaResolver()
Class<?>
getCollectionType()
String
getCollectionTypeName()
String
getContentTypeHeader()
Whether the data format should set the Content-Type header with the type from the data format.String
getDataFormatName()
String
getDisableFeatures()
String
getDropRootNode()
String
getEnableFeatures()
String
getInclude()
Class<?>
getJsonView()
String
getJsonViewTypeName()
JsonLibrary
getLibrary()
String
getModuleClassNames()
String
getModuleRefs()
String
getNamingStrategy()
String
getObjectMapper()
String
getPermissions()
String
getPrettyPrint()
String
getSchemaResolver()
String
getTimezone()
Class<?>
getUnmarshalType()
String
getUnmarshalTypeName()
String
getUseDefaultObjectMapper()
String
getUseList()
JsonDataFormat
include(String include)
JsonDataFormat
jsonView(Class<?> jsonView)
JsonDataFormat
library(JsonLibrary library)
JsonDataFormat
moduleClassNames(String moduleClassNames)
JsonDataFormat
moduleRefs(String moduleRefs)
JsonDataFormat
namingStrategy(String namingStrategy)
JsonDataFormat
objectMapper(String objectMapper)
JsonDataFormat
permissions(String permissions)
JsonDataFormat
prettyPrint(boolean prettyPrint)
JsonDataFormat
prettyPrint(String prettyPrint)
void
setAllowJmsType(String allowJmsType)
Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.void
setAllowUnmarshallType(String allowUnmarshallType)
If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling.void
setAutoDiscoverObjectMapper(String autoDiscoverObjectMapper)
If set to true then Jackson will look for an objectMapper to use from the registryvoid
setAutoDiscoverSchemaResolver(String autoDiscoverSchemaResolver)
When not disabled, the SchemaResolver will be looked up into the registryvoid
setCollectionType(Class<?> collectionType)
void
setCollectionTypeName(String collectionTypeName)
Refers to a custom collection type to lookup in the registry to use.void
setContentTypeHeader(String contentTypeHeader)
Whether the data format should set the Content-Type header with the type from the data format.void
setDisableFeatures(String disableFeatures)
Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper.void
setDropRootNode(String dropRootNode)
Whether XStream will drop the root node in the generated JSon.void
setEnableFeatures(String enableFeatures)
Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper.void
setInclude(String include)
If you want to marshal a pojo to JSON, and the pojo has some fields with null values.void
setJsonView(Class<?> jsonView)
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output.void
setJsonViewTypeName(String jsonViewTypeName)
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output.void
setLibrary(JsonLibrary library)
Which json library to use.void
setModuleClassNames(String moduleClassNames)
To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names.void
setModuleRefs(String moduleRefs)
To use custom Jackson modules referred from the Camel registry.void
setNamingStrategy(String namingStrategy)
If set then Jackson will use the the defined Property Naming Strategy.void
setObjectMapper(String objectMapper)
Lookup and use the existing ObjectMapper with the given id when using Jackson.void
setPermissions(Class<?>... type)
To add permission for the given pojo classes.void
setPermissions(String permissions)
Adds permissions that controls which Java packages and classes XStream is allowed to use during unmarshal from xml/json to Java beans.void
setPrettyPrint(String prettyPrint)
To enable pretty printing output nicely formatted.void
setSchemaResolver(String schemaResolver)
Optional schema resolver used to lookup schemas for the data in transit.void
setTimezone(String timezone)
If set then Jackson will use the Timezone when marshalling/unmarshalling.void
setUnmarshalType(Class<?> unmarshalType)
Class of the java type to use when unmarshallingvoid
setUnmarshalTypeName(String unmarshalTypeName)
Class name of the java type to use when unmarshallingvoid
setUseDefaultObjectMapper(String useDefaultObjectMapper)
Whether to lookup and use default Jackson ObjectMapper from the registry.void
setUseList(String useList)
To unmarshal to a List of Map or a List of Pojo.JsonDataFormat
timezone(String timezone)
JsonDataFormat
unmarshalType(Class<?> unmarshalType)
JsonDataFormat
unmarshalType(String unmarshalType)
JsonDataFormat
useDefaultObjectMapper(boolean useDefaultObjectMapper)
JsonDataFormat
useDefaultObjectMapper(String useDefaultObjectMapper)
JsonDataFormat
useList(boolean useList)
JsonDataFormat
useList(String useList)
-
Methods inherited from class org.apache.camel.model.DataFormatDefinition
getDataFormat, getShortName, setDataFormat, setDataFormatName
-
Methods inherited from class org.apache.camel.model.IdentifiedType
getId, setId
-
-
-
-
Constructor Detail
-
JsonDataFormat
public JsonDataFormat()
-
JsonDataFormat
public JsonDataFormat(JsonLibrary library)
-
-
Method Detail
-
getDataFormatName
public String getDataFormatName()
- Overrides:
getDataFormatName
in classDataFormatDefinition
-
getContentTypeHeader
public String getContentTypeHeader()
Description copied from interface:ContentTypeHeaderAware
Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.- Specified by:
getContentTypeHeader
in interfaceContentTypeHeaderAware
-
setContentTypeHeader
public void setContentTypeHeader(String contentTypeHeader)
Description copied from interface:ContentTypeHeaderAware
Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.- Specified by:
setContentTypeHeader
in interfaceContentTypeHeaderAware
-
getObjectMapper
public String getObjectMapper()
-
setObjectMapper
public void setObjectMapper(String objectMapper)
Lookup and use the existing ObjectMapper with the given id when using Jackson.
-
getUseDefaultObjectMapper
public String getUseDefaultObjectMapper()
-
setUseDefaultObjectMapper
public void setUseDefaultObjectMapper(String useDefaultObjectMapper)
Whether to lookup and use default Jackson ObjectMapper from the registry.
-
getPrettyPrint
public String getPrettyPrint()
-
setPrettyPrint
public void setPrettyPrint(String prettyPrint)
To enable pretty printing output nicely formatted. Is by default false.
-
getUnmarshalTypeName
public String getUnmarshalTypeName()
-
setUnmarshalTypeName
public void setUnmarshalTypeName(String unmarshalTypeName)
Class name of the java type to use when unmarshalling
-
getUnmarshalType
public Class<?> getUnmarshalType()
-
setUnmarshalType
public void setUnmarshalType(Class<?> unmarshalType)
Class of the java type to use when unmarshalling
-
getLibrary
public JsonLibrary getLibrary()
-
setLibrary
public void setLibrary(JsonLibrary library)
Which json library to use.
-
getJsonViewTypeName
public String getJsonViewTypeName()
-
setJsonViewTypeName
public void setJsonViewTypeName(String jsonViewTypeName)
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has @JsonView annotations
-
getJsonView
public Class<?> getJsonView()
-
setJsonView
public void setJsonView(Class<?> jsonView)
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has @JsonView annotations
-
getInclude
public String getInclude()
-
setInclude
public void setInclude(String include)
If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL
-
getAllowJmsType
public String getAllowJmsType()
-
setAllowJmsType
public void setAllowJmsType(String allowJmsType)
Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.
-
getCollectionTypeName
public String getCollectionTypeName()
-
setCollectionTypeName
public void setCollectionTypeName(String collectionTypeName)
Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows using different collection types than java.util.Collection based as default.
-
getCollectionType
public Class<?> getCollectionType()
-
setCollectionType
public void setCollectionType(Class<?> collectionType)
-
getUseList
public String getUseList()
-
setUseList
public void setUseList(String useList)
To unmarshal to a List of Map or a List of Pojo.
-
getModuleClassNames
public String getModuleClassNames()
-
setModuleClassNames
public void setModuleClassNames(String moduleClassNames)
To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma.
-
getModuleRefs
public String getModuleRefs()
-
setModuleRefs
public void setModuleRefs(String moduleRefs)
To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma.
-
getEnableFeatures
public String getEnableFeatures()
-
setEnableFeatures
public void setEnableFeatures(String enableFeatures)
Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma
-
getDisableFeatures
public String getDisableFeatures()
-
setDisableFeatures
public void setDisableFeatures(String disableFeatures)
Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma
-
getPermissions
public String getPermissions()
-
setPermissions
public void setPermissions(String permissions)
Adds permissions that controls which Java packages and classes XStream is allowed to use during unmarshal from xml/json to Java beans. A permission must be configured either here or globally using a JVM system property. The permission can be specified in a syntax where a plus sign is allow, and minus sign is deny.
Wildcards is supported by using .* as prefix. For example to allow com.foo and all subpackages then specfy +com.foo.*. Multiple permissions can be configured separated by comma, such as +com.foo.*,-com.foo.bar.MySecretBean.
The following default permission is always included: "-*,java.lang.*,java.util.*" unless its overridden by specifying a JVM system property with they key org.apache.camel.xstream.permissions.
-
setPermissions
public void setPermissions(Class<?>... type)
To add permission for the given pojo classes.- Parameters:
type
- the pojo class(es) xstream should use as allowed permission- See Also:
setPermissions(String)
-
getAllowUnmarshallType
public String getAllowUnmarshallType()
-
setAllowUnmarshallType
public void setAllowUnmarshallType(String allowUnmarshallType)
If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.
-
getTimezone
public String getTimezone()
-
setTimezone
public void setTimezone(String timezone)
If set then Jackson will use the Timezone when marshalling/unmarshalling. This option will have no effect on the others Json DataFormat, like gson, fastjson and xstream.
-
getAutoDiscoverObjectMapper
public String getAutoDiscoverObjectMapper()
-
setAutoDiscoverObjectMapper
public void setAutoDiscoverObjectMapper(String autoDiscoverObjectMapper)
If set to true then Jackson will look for an objectMapper to use from the registry
-
getDropRootNode
public String getDropRootNode()
-
setDropRootNode
public void setDropRootNode(String dropRootNode)
Whether XStream will drop the root node in the generated JSon. You may want to enable this when using POJOs; as then the written object will include the class name as root node, which is often not intended to be written in the JSON output.
-
setSchemaResolver
public void setSchemaResolver(String schemaResolver)
Optional schema resolver used to lookup schemas for the data in transit.
-
getSchemaResolver
public String getSchemaResolver()
-
getAutoDiscoverSchemaResolver
public String getAutoDiscoverSchemaResolver()
-
setAutoDiscoverSchemaResolver
public void setAutoDiscoverSchemaResolver(String autoDiscoverSchemaResolver)
When not disabled, the SchemaResolver will be looked up into the registry
-
getNamingStrategy
public String getNamingStrategy()
-
setNamingStrategy
public void setNamingStrategy(String namingStrategy)
If set then Jackson will use the the defined Property Naming Strategy. Possible values are: LOWER_CAMEL_CASE, LOWER_DOT_CASE, LOWER_CASE, KEBAB_CASE, SNAKE_CASE and UPPER_CAMEL_CASE
-
objectMapper
public JsonDataFormat objectMapper(String objectMapper)
-
useDefaultObjectMapper
public JsonDataFormat useDefaultObjectMapper(boolean useDefaultObjectMapper)
-
useDefaultObjectMapper
public JsonDataFormat useDefaultObjectMapper(String useDefaultObjectMapper)
-
prettyPrint
public JsonDataFormat prettyPrint(boolean prettyPrint)
-
prettyPrint
public JsonDataFormat prettyPrint(String prettyPrint)
-
library
public JsonDataFormat library(JsonLibrary library)
-
unmarshalType
public JsonDataFormat unmarshalType(String unmarshalType)
-
unmarshalType
public JsonDataFormat unmarshalType(Class<?> unmarshalType)
-
jsonView
public JsonDataFormat jsonView(Class<?> jsonView)
-
include
public JsonDataFormat include(String include)
-
allowJmsType
public JsonDataFormat allowJmsType(boolean allowJmsType)
-
allowJmsType
public JsonDataFormat allowJmsType(String allowJmsType)
-
collectionType
public JsonDataFormat collectionType(String collectionType)
-
collectionType
public JsonDataFormat collectionType(Class<?> collectionType)
-
useList
public JsonDataFormat useList(boolean useList)
-
useList
public JsonDataFormat useList(String useList)
-
moduleClassNames
public JsonDataFormat moduleClassNames(String moduleClassNames)
-
moduleRefs
public JsonDataFormat moduleRefs(String moduleRefs)
-
enableFeatures
public JsonDataFormat enableFeatures(String enableFeatures)
-
disableFeatures
public JsonDataFormat disableFeatures(String disableFeatures)
-
permissions
public JsonDataFormat permissions(String permissions)
-
allowUnmarshallType
public JsonDataFormat allowUnmarshallType(boolean allowUnmarshallType)
-
allowUnmarshallType
public JsonDataFormat allowUnmarshallType(String allowUnmarshallType)
-
timezone
public JsonDataFormat timezone(String timezone)
-
autoDiscoverObjectMapper
public JsonDataFormat autoDiscoverObjectMapper(boolean autoDiscoverObjectMapper)
-
autoDiscoverObjectMapper
public JsonDataFormat autoDiscoverObjectMapper(String autoDiscoverObjectMapper)
-
dropRootNode
public JsonDataFormat dropRootNode(boolean dropRootNode)
-
dropRootNode
public JsonDataFormat dropRootNode(String dropRootNode)
-
namingStrategy
public JsonDataFormat namingStrategy(String namingStrategy)
-
-