Class AbstractJacksonDataFormat
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.component.jackson.AbstractJacksonDataFormat
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.DataFormat
,org.apache.camel.spi.DataFormatContentTypeHeader
,org.apache.camel.spi.DataFormatName
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
- Direct Known Subclasses:
JacksonDataFormat
public abstract class AbstractJacksonDataFormat extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName, org.apache.camel.spi.DataFormatContentTypeHeader, org.apache.camel.CamelContextAware
Abstract superclass of Jackson based data formats.
-
-
Constructor Summary
Constructors Constructor Description AbstractJacksonDataFormat()
Use the default JacksonObjectMapper
andObject
AbstractJacksonDataFormat(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> unmarshalType)
Use a custom Jackson mapper and and unmarshal typeAbstractJacksonDataFormat(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> unmarshalType, Class<?> jsonView)
Use a custom Jackson mapper, unmarshal type and JSON viewAbstractJacksonDataFormat(Class<?> unmarshalType)
Use the default JacksonObjectMapper
and with a custom unmarshal typeAbstractJacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView)
Use the default JacksonObjectMapper
and with a custom unmarshal type and JSON view
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addModule(com.fasterxml.jackson.databind.Module module)
To use the custom Jackson moduleprotected abstract com.fasterxml.jackson.databind.ObjectMapper
createNewObjectMapper()
void
disableFeature(com.fasterxml.jackson.databind.DeserializationFeature feature)
void
disableFeature(com.fasterxml.jackson.databind.MapperFeature feature)
void
disableFeature(com.fasterxml.jackson.databind.SerializationFeature feature)
protected void
doInit()
protected void
doStart()
protected void
doStop()
void
enableFeature(com.fasterxml.jackson.databind.DeserializationFeature feature)
void
enableFeature(com.fasterxml.jackson.databind.MapperFeature feature)
void
enableFeature(com.fasterxml.jackson.databind.SerializationFeature feature)
org.apache.camel.CamelContext
getCamelContext()
Class<? extends Collection>
getCollectionType()
String
getCollectionTypeName()
abstract String
getDataFormatName()
protected abstract String
getDefaultContentType()
String
getDisableFeatures()
String
getEnableFeatures()
String
getInclude()
Class<?>
getJsonView()
String
getJsonViewTypeName()
String
getModuleClassNames()
String
getModuleRefs()
List<com.fasterxml.jackson.databind.Module>
getModules()
String
getNamingStrategy()
com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
protected abstract Class<? extends com.fasterxml.jackson.databind.ObjectMapper>
getObjectMapperClass()
SchemaResolver
getSchemaResolver()
TimeZone
getTimezone()
Class<?>
getUnmarshalType()
String
getUnmarshalTypeName()
boolean
isAllowJmsType()
boolean
isAllowUnmarshallType()
boolean
isAutoDiscoverObjectMapper()
boolean
isAutoDiscoverSchemaResolver()
boolean
isContentTypeHeader()
boolean
isEnableJacksonTypeConverter()
boolean
isPrettyPrint()
boolean
isUseDefaultObjectMapper()
boolean
isUseList()
void
marshal(org.apache.camel.Exchange exchange, Object graph, OutputStream stream)
void
setAllowJmsType(boolean allowJmsType)
Allows jackson to use the JMSType header as an indicator what the classname is for unmarshaling content to POJOvoid
setAllowUnmarshallType(boolean allowJacksonUnmarshallType)
If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling.void
setAutoDiscoverObjectMapper(boolean autoDiscoverObjectMapper)
If set to true and useDefaultObjectMapper is true, then Jackson will look for an objectMapper in the registry.void
setAutoDiscoverSchemaResolver(boolean autoDiscoverSchemaResolver)
When not disabled, the SchemaResolver will be looked up into the registryvoid
setCamelContext(org.apache.camel.CamelContext camelContext)
void
setCollectionType(Class<? extends Collection> collectionType)
void
setCollectionTypeName(String collectionTypeName)
void
setContentTypeHeader(boolean contentTypeHeader)
If enabled then Jackson will set the Content-Type header to the correct mime type when marshalling.void
setDisableFeatures(String disableFeatures)
Set of features to disable on the JacksonObjectMapper
.void
setEnableFeatures(String enableFeatures)
Set of features to enable on the JacksonObjectMapper
.void
setEnableJacksonTypeConverter(boolean enableJacksonTypeConverter)
If enabled then Jackson is allowed to attempt to be used during Camels type converter as aFallbackConverter
that attempts to convert POJOs to/fromMap
/List
types.void
setInclude(String include)
void
setJsonView(Class<?> jsonView)
void
setJsonViewTypeName(String jsonViewTypeName)
void
setModuleClassNames(String moduleClassNames)
To use custom JacksonModule
s specified as a String with FQN class names.void
setModuleRefs(String moduleRefs)
To use custom Jackson modules referred from the Camel registry.void
setModules(List<com.fasterxml.jackson.databind.Module> modules)
To use custom JacksonModule
svoid
setNamingStrategy(String namingStrategy)
void
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
void
setPrettyPrint(boolean prettyPrint)
void
setSchemaResolver(SchemaResolver schemaResolver)
Optional schema resolver used to lookup schemas for the data in transit.void
setTimezone(TimeZone timezone)
If set then Jackson will use the Timezone when marshalling/unmarshalling.void
setUnmarshalType(Class<?> unmarshalType)
void
setUnmarshalTypeName(String unmarshalTypeName)
void
setUseDefaultObjectMapper(boolean useDefaultObjectMapper)
void
setUseList(boolean useList)
Object
unmarshal(org.apache.camel.Exchange exchange, InputStream stream)
void
useList()
UsesArrayList
when unmarshalling.void
useMap()
UsesHashMap
when unmarshalling.-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
AbstractJacksonDataFormat
public AbstractJacksonDataFormat()
Use the default JacksonObjectMapper
andObject
-
AbstractJacksonDataFormat
public AbstractJacksonDataFormat(Class<?> unmarshalType)
Use the default JacksonObjectMapper
and with a custom unmarshal type- Parameters:
unmarshalType
- the custom unmarshal type
-
AbstractJacksonDataFormat
public AbstractJacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView)
Use the default JacksonObjectMapper
and with a custom unmarshal type and JSON view- Parameters:
unmarshalType
- the custom unmarshal typejsonView
- marker class to specify properties to be included during marshalling. See also https://github.com/FasterXML/jackson-annotations/blob/master/src/main/java/com/fasterxml/jackson/annotation/JsonView.java
-
AbstractJacksonDataFormat
public AbstractJacksonDataFormat(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> unmarshalType)
Use a custom Jackson mapper and and unmarshal type- Parameters:
mapper
- the custom mapperunmarshalType
- the custom unmarshal type
-
AbstractJacksonDataFormat
public AbstractJacksonDataFormat(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> unmarshalType, Class<?> jsonView)
Use a custom Jackson mapper, unmarshal type and JSON view- Parameters:
mapper
- the custom mapperunmarshalType
- the custom unmarshal typejsonView
- marker class to specify properties to be included during marshalling. See also https://github.com/FasterXML/jackson-annotations/blob/master/src/main/java/com/fasterxml/jackson/annotation/JsonView.java
-
-
Method Detail
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
marshal
public void marshal(org.apache.camel.Exchange exchange, Object graph, OutputStream stream) throws Exception
- Specified by:
marshal
in interfaceorg.apache.camel.spi.DataFormat
- Throws:
Exception
-
unmarshal
public Object unmarshal(org.apache.camel.Exchange exchange, InputStream stream) throws Exception
- Specified by:
unmarshal
in interfaceorg.apache.camel.spi.DataFormat
- Throws:
Exception
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
setObjectMapper
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
isUseDefaultObjectMapper
public boolean isUseDefaultObjectMapper()
-
setUseDefaultObjectMapper
public void setUseDefaultObjectMapper(boolean useDefaultObjectMapper)
-
getUnmarshalType
public Class<?> getUnmarshalType()
-
setUnmarshalType
public void setUnmarshalType(Class<?> unmarshalType)
-
getUnmarshalTypeName
public String getUnmarshalTypeName()
-
setUnmarshalTypeName
public void setUnmarshalTypeName(String unmarshalTypeName)
-
getCollectionType
public Class<? extends Collection> getCollectionType()
-
setCollectionType
public void setCollectionType(Class<? extends Collection> collectionType)
-
getCollectionTypeName
public String getCollectionTypeName()
-
setCollectionTypeName
public void setCollectionTypeName(String collectionTypeName)
-
getJsonView
public Class<?> getJsonView()
-
setJsonView
public void setJsonView(Class<?> jsonView)
-
getJsonViewTypeName
public String getJsonViewTypeName()
-
setJsonViewTypeName
public void setJsonViewTypeName(String jsonViewTypeName)
-
getInclude
public String getInclude()
-
setInclude
public void setInclude(String include)
-
isAllowJmsType
public boolean isAllowJmsType()
-
isPrettyPrint
public boolean isPrettyPrint()
-
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint)
-
isUseList
public boolean isUseList()
-
setUseList
public void setUseList(boolean useList)
-
getModules
public List<com.fasterxml.jackson.databind.Module> getModules()
-
getNamingStrategy
public String getNamingStrategy()
-
setNamingStrategy
public void setNamingStrategy(String namingStrategy)
-
setModules
public void setModules(List<com.fasterxml.jackson.databind.Module> modules)
To use custom JacksonModule
s
-
getModuleClassNames
public String getModuleClassNames()
-
addModule
public void addModule(com.fasterxml.jackson.databind.Module module)
To use the custom Jackson module
-
setModuleClassNames
public void setModuleClassNames(String moduleClassNames)
To use custom JacksonModule
s 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.
-
useList
public void useList()
UsesArrayList
when unmarshalling.
-
useMap
public void useMap()
UsesHashMap
when unmarshalling.
-
setAllowJmsType
public void setAllowJmsType(boolean allowJmsType)
Allows jackson to use the JMSType header as an indicator what the classname is for unmarshaling content to POJO By default this option is false.
-
isEnableJacksonTypeConverter
public boolean isEnableJacksonTypeConverter()
-
setEnableJacksonTypeConverter
public void setEnableJacksonTypeConverter(boolean enableJacksonTypeConverter)
If enabled then Jackson is allowed to attempt to be used during Camels type converter as aFallbackConverter
that attempts to convert POJOs to/fromMap
/List
types. This should only be enabled when desired to be used.
-
isAllowUnmarshallType
public boolean isAllowUnmarshallType()
-
setAllowUnmarshallType
public void setAllowUnmarshallType(boolean allowJacksonUnmarshallType)
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.
-
isContentTypeHeader
public boolean isContentTypeHeader()
-
setContentTypeHeader
public void setContentTypeHeader(boolean contentTypeHeader)
If enabled then Jackson will set the Content-Type header to the correct mime type when marshalling.- Specified by:
setContentTypeHeader
in interfaceorg.apache.camel.spi.DataFormatContentTypeHeader
-
getTimezone
public TimeZone getTimezone()
-
setTimezone
public void setTimezone(TimeZone timezone)
If set then Jackson will use the Timezone when marshalling/unmarshalling.
-
isAutoDiscoverObjectMapper
public boolean isAutoDiscoverObjectMapper()
-
setAutoDiscoverObjectMapper
public void setAutoDiscoverObjectMapper(boolean autoDiscoverObjectMapper)
If set to true and useDefaultObjectMapper is true, then Jackson will look for an objectMapper in the registry.
-
getSchemaResolver
public SchemaResolver getSchemaResolver()
-
setSchemaResolver
public void setSchemaResolver(SchemaResolver schemaResolver)
Optional schema resolver used to lookup schemas for the data in transit.
-
isAutoDiscoverSchemaResolver
public boolean isAutoDiscoverSchemaResolver()
-
setAutoDiscoverSchemaResolver
public void setAutoDiscoverSchemaResolver(boolean autoDiscoverSchemaResolver)
When not disabled, the SchemaResolver will be looked up into the registry
-
getEnableFeatures
public String getEnableFeatures()
-
setEnableFeatures
public void setEnableFeatures(String enableFeatures)
Set of features to enable on the JacksonObjectMapper
. The features should be a name that matches a enum fromSerializationFeature
,DeserializationFeature
, orMapperFeature
.
-
getDisableFeatures
public String getDisableFeatures()
-
setDisableFeatures
public void setDisableFeatures(String disableFeatures)
Set of features to disable on the JacksonObjectMapper
. The features should be a name that matches a enum fromSerializationFeature
,DeserializationFeature
, orMapperFeature
.
-
enableFeature
public void enableFeature(com.fasterxml.jackson.databind.SerializationFeature feature)
-
enableFeature
public void enableFeature(com.fasterxml.jackson.databind.DeserializationFeature feature)
-
enableFeature
public void enableFeature(com.fasterxml.jackson.databind.MapperFeature feature)
-
disableFeature
public void disableFeature(com.fasterxml.jackson.databind.SerializationFeature feature)
-
disableFeature
public void disableFeature(com.fasterxml.jackson.databind.DeserializationFeature feature)
-
disableFeature
public void disableFeature(com.fasterxml.jackson.databind.MapperFeature feature)
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
getDataFormatName
public abstract String getDataFormatName()
- Specified by:
getDataFormatName
in interfaceorg.apache.camel.spi.DataFormatName
-
createNewObjectMapper
protected abstract com.fasterxml.jackson.databind.ObjectMapper createNewObjectMapper()
-
getObjectMapperClass
protected abstract Class<? extends com.fasterxml.jackson.databind.ObjectMapper> getObjectMapperClass()
-
getDefaultContentType
protected abstract String getDefaultContentType()
-
-