This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit e75c436ccb3efc347ccc5b62db783a02a0d44a98 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Oct 30 09:24:29 2019 +0100 CAMEL-14101 - Fixed CS --- .../camel/component/jackson/JacksonDataFormat.java | 1137 ++++++++++---------- .../component/jackson/ListJacksonDataFormat.java | 5 +- .../jackson/converter/JacksonTypeConverters.java | 48 +- .../component/jackson/JacksonConcurrentTest.java | 9 +- .../component/jackson/JacksonDataFormatTest.java | 2 +- .../jackson/JacksonJsonDataFormatTest.java | 2 +- .../jackson/JacksonMarshalDateTimezoneTest.java | 3 +- .../jackson/JacksonMarshalUnmarshalListTest.java | 6 +- .../JacksonNotUseDefaultObjectMapperTest.java | 3 +- .../jackson/JacksonObjectListSplitTest.java | 7 +- .../jackson/JacksonObjectMapperRegistryTest.java | 8 +- .../SpringJacksonMarshalUnmarshalListTest.java | 6 +- .../SpringJacksonObjectMapperRegistryTest.java | 4 +- .../camel/component/jackson/TestJAXBPojo.java | 4 +- .../camel/component/jackson/TestOtherPojo.java | 2 +- .../apache/camel/component/jackson/TestPojo.java | 4 +- .../camel/component/jackson/TestPojoView.java | 6 +- .../org/apache/camel/component/jackson/Views.java | 7 +- .../converter/JacksonConversionsPojoTest.java | 5 +- .../converter/JacksonConversionsSimpleTest.java | 3 +- .../jackson/converter/JacksonConversionsTest.java | 5 +- 21 files changed, 641 insertions(+), 635 deletions(-) diff --git a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java index c205e3b..35f5e4b 100644 --- a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java +++ b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java @@ -53,575 +53,572 @@ import org.apache.camel.support.service.ServiceSupport; @Dataformat("json-jackson") public class JacksonDataFormat extends ServiceSupport implements DataFormat, DataFormatName, CamelContextAware { - private CamelContext camelContext; - private ObjectMapper objectMapper; - private boolean useDefaultObjectMapper = true; - private Class<? extends Collection> collectionType; - private List<Module> modules; - private String moduleClassNames; - private String moduleRefs; - private Class<?> unmarshalType; - private Class<?> jsonView; - private String include; - private boolean prettyPrint; - private boolean allowJmsType; - private boolean useList; - private boolean enableJaxbAnnotationModule; - private String enableFeatures; - private String disableFeatures; - private boolean enableJacksonTypeConverter; - private boolean allowUnmarshallType; - private boolean contentTypeHeader = true; - private TimeZone timezone; - private boolean autoDiscoverObjectMapper; - - /** - * Use the default Jackson {@link ObjectMapper} and {@link Object} - */ - public JacksonDataFormat() { - this(Object.class); - } - - /** - * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal type - * - * @param unmarshalType the custom unmarshal type - */ - public JacksonDataFormat(Class<?> unmarshalType) { - this(unmarshalType, null); - } - - /** - * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal type - * and JSON view - * - * @param unmarshalType the custom unmarshal type - * @param jsonView marker class to specify properties to be included during - * marshalling. See also - * http://wiki.fasterxml.com/JacksonJsonViews - */ - public JacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView) { - this(unmarshalType, jsonView, true); - } - - /** - * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal type - * and JSON view - * - * @param unmarshalType the custom unmarshal type - * @param jsonView marker class to specify properties to be - * included during marshalling. See also - * http://wiki.fasterxml.com/JacksonJsonViews - * @param enableJaxbAnnotationModule if it is true, will enable the - * JaxbAnnotationModule. - */ - public JacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView, boolean enableJaxbAnnotationModule) { - this.unmarshalType = unmarshalType; - this.jsonView = jsonView; - this.enableJaxbAnnotationModule = enableJaxbAnnotationModule; - } - - /** - * Use a custom Jackson mapper and and unmarshal type - * - * @param mapper the custom mapper - * @param unmarshalType the custom unmarshal type - */ - public JacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType) { - this(mapper, unmarshalType, null); - } - - /** - * Use a custom Jackson mapper, unmarshal type and JSON view - * - * @param mapper the custom mapper - * @param unmarshalType the custom unmarshal type - * @param jsonView marker class to specify properties to be included during - * marshalling. See also - * http://wiki.fasterxml.com/JacksonJsonViews - */ - public JacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType, Class<?> jsonView) { - this.objectMapper = mapper; - this.unmarshalType = unmarshalType; - this.jsonView = jsonView; - } - - @Override - public String getDataFormatName() { - return "json-jackson"; - } - - @Override - public CamelContext getCamelContext() { - return camelContext; - } - - @Override - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } - - @Override - public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { - this.objectMapper.writerWithView(jsonView).writeValue(stream, graph); - - if (contentTypeHeader) { - if (exchange.hasOut()) { - exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); - } else { - exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); - } - } - } - - @Override - public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { - - // is there a header with the unmarshal type? - Class<?> clazz = unmarshalType; - String type = null; - if (allowUnmarshallType) { - type = exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class); - } - if (type == null && isAllowJmsType()) { - type = exchange.getIn().getHeader("JMSType", String.class); - } - if (type != null) { - clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type); - } - if (collectionType != null) { - CollectionType collType = objectMapper.getTypeFactory().constructCollectionType(collectionType, clazz); - return this.objectMapper.readValue(stream, collType); - } else { - return this.objectMapper.readValue(stream, clazz); - } - } - - // Properties - // ------------------------------------------------------------------------- - - public ObjectMapper getObjectMapper() { - return this.objectMapper; - } - - public void setObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - public boolean isUseDefaultObjectMapper() { - return useDefaultObjectMapper; - } - - public void setUseDefaultObjectMapper(boolean useDefaultObjectMapper) { - this.useDefaultObjectMapper = useDefaultObjectMapper; - } - - public Class<?> getUnmarshalType() { - return this.unmarshalType; - } - - public void setUnmarshalType(Class<?> unmarshalType) { - this.unmarshalType = unmarshalType; - } - - public Class<? extends Collection> getCollectionType() { - return collectionType; - } - - public void setCollectionType(Class<? extends Collection> collectionType) { - this.collectionType = collectionType; - } - - public Class<?> getJsonView() { - return jsonView; - } - - public void setJsonView(Class<?> jsonView) { - this.jsonView = jsonView; - } - - public String getInclude() { - return include; - } - - public void setInclude(String include) { - this.include = include; - } - - public boolean isAllowJmsType() { - return allowJmsType; - } - - public boolean isPrettyPrint() { - return prettyPrint; - } - - public void setPrettyPrint(boolean prettyPrint) { - this.prettyPrint = prettyPrint; - } - - public boolean isUseList() { - return useList; - } - - public void setUseList(boolean useList) { - this.useList = useList; - } - - public boolean isEnableJaxbAnnotationModule() { - return enableJaxbAnnotationModule; - } - - public void setEnableJaxbAnnotationModule(boolean enableJaxbAnnotationModule) { - this.enableJaxbAnnotationModule = enableJaxbAnnotationModule; - } - - public List<Module> getModules() { - return modules; - } - - /** - * To use custom Jackson {@link Module}s - */ - public void setModules(List<Module> modules) { - this.modules = modules; - } - - public String getModuleClassNames() { - return moduleClassNames; - } - - /** - * To use the custom Jackson module - */ - public void addModule(Module module) { - if (this.modules == null) { - this.modules = new ArrayList<>(); - } - this.modules.add(module); - } - - /** - * To use custom Jackson {@link Module}s specified as a String with FQN class - * names. Multiple classes can be separated by comma. - */ - public void setModuleClassNames(String moduleClassNames) { - this.moduleClassNames = moduleClassNames; - } - - public String getModuleRefs() { - return moduleRefs; - } - - /** - * To use custom Jackson modules referred from the Camel registry. Multiple - * modules can be separated by comma. - */ - public void setModuleRefs(String moduleRefs) { - this.moduleRefs = moduleRefs; - } - - /** - * Uses {@link java.util.ArrayList} when unmarshalling. - */ - public void useList() { - setCollectionType(ArrayList.class); - } - - /** - * Uses {@link java.util.HashMap} when unmarshalling. - */ - public void useMap() { - setCollectionType(null); - setUnmarshalType(HashMap.class); - } - - /** - * Allows jackson to use the <tt>JMSType</tt> header as an indicator what the - * classname is for unmarshaling json content to POJO - * <p/> - * By default this option is <tt>false</tt>. - */ - public void setAllowJmsType(boolean allowJmsType) { - this.allowJmsType = allowJmsType; - } - - public boolean isEnableJacksonTypeConverter() { - return enableJacksonTypeConverter; - } - - /** - * If enabled then Jackson is allowed to attempt to be used during Camels - * <a href="https://camel.apache.org/type-converter.html">type converter</a> as - * a {@link org.apache.camel.FallbackConverter} that attempts to convert POJOs - * to/from {@link Map}/{@link List} types. - * <p/> - * This should only be enabled when desired to be used. - */ - public void setEnableJacksonTypeConverter(boolean enableJacksonTypeConverter) { - this.enableJacksonTypeConverter = enableJacksonTypeConverter; - } - - public boolean isAllowUnmarshallType() { - return allowUnmarshallType; - } - - /** - * If enabled then Jackson is allowed to attempt to use the - * CamelJacksonUnmarshalType header during the unmarshalling. - * <p/> - * This should only be enabled when desired to be used. - */ - public void setAllowUnmarshallType(boolean allowJacksonUnmarshallType) { - this.allowUnmarshallType = allowJacksonUnmarshallType; - } - - public boolean isContentTypeHeader() { - return contentTypeHeader; - } - - /** - * If enabled then Jackson will set the Content-Type header to - * <tt>application/json</tt> when marshalling. - */ - public void setContentTypeHeader(boolean contentTypeHeader) { - this.contentTypeHeader = contentTypeHeader; - } - - public TimeZone getTimezone() { - return timezone; - } - - /** - * If set then Jackson will use the Timezone when marshalling/unmarshalling. - */ - public void setTimezone(TimeZone timezone) { - this.timezone = timezone; - } - - public boolean isAutoDiscoverObjectMapper() { - return autoDiscoverObjectMapper; - } - - /** - * If set to true then Jackson will lookup for an objectMapper into the registry - */ - public void setAutoDiscoverObjectMapper(boolean autoDiscoverObjectMapper) { - this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; - } - - public String getEnableFeatures() { - return enableFeatures; - } - - /** - * Set of features to enable on the Jackson {@link ObjectMapper}. The features - * should be a name that matches a enum from {@link SerializationFeature}, - * {@link DeserializationFeature}, or {@link MapperFeature}. - */ - public void setEnableFeatures(String enableFeatures) { - this.enableFeatures = enableFeatures; - } - - public String getDisableFeatures() { - return disableFeatures; - } - - /** - * Set of features to disable on the Jackson {@link ObjectMapper}. The features - * should be a name that matches a enum from {@link SerializationFeature}, - * {@link DeserializationFeature}, or {@link MapperFeature}. - */ - public void setDisableFeatures(String disableFeatures) { - this.disableFeatures = disableFeatures; - } - - public void enableFeature(SerializationFeature feature) { - if (enableFeatures == null) { - enableFeatures = feature.name(); - } else { - enableFeatures += "," + feature.name(); - } - } - - public void enableFeature(DeserializationFeature feature) { - if (enableFeatures == null) { - enableFeatures = feature.name(); - } else { - enableFeatures += "," + feature.name(); - } - } - - public void enableFeature(MapperFeature feature) { - if (enableFeatures == null) { - enableFeatures = feature.name(); - } else { - enableFeatures += "," + feature.name(); - } - } - - public void disableFeature(SerializationFeature feature) { - if (disableFeatures == null) { - disableFeatures = feature.name(); - } else { - disableFeatures += "," + feature.name(); - } - } - - public void disableFeature(DeserializationFeature feature) { - if (disableFeatures == null) { - disableFeatures = feature.name(); - } else { - disableFeatures += "," + feature.name(); - } - } - - public void disableFeature(MapperFeature feature) { - if (disableFeatures == null) { - disableFeatures = feature.name(); - } else { - disableFeatures += "," + feature.name(); - } - } - - @Override - protected void doStart() throws Exception { - boolean objectMapperFoundRegistry = false; - if (objectMapper == null) { - // lookup if there is a single default mapper we can use - if (useDefaultObjectMapper && camelContext != null) { - if (isAutoDiscoverObjectMapper()) { - Set<ObjectMapper> set = camelContext.getRegistry().findByType(ObjectMapper.class); - if (set.size() == 1) { - objectMapper = set.iterator().next(); - log.info("Found single ObjectMapper in Registry to use: {}", objectMapper); - objectMapperFoundRegistry = true; - } else if (set.size() > 1) { - log.debug( - "Found {} ObjectMapper in Registry cannot use as default as there are more than one instance.", - set.size()); - } - } else { - log.warn("The option autoDiscoverObjectMapper is set to false, Camel won't search in the registry"); - } - } - if (objectMapper == null) { - objectMapper = new ObjectMapper(); - log.debug("Creating new ObjectMapper to use: {}", objectMapper); - } - } - - if (!objectMapperFoundRegistry) { - if (enableJaxbAnnotationModule) { - // Enables JAXB processing - JaxbAnnotationModule module = new JaxbAnnotationModule(); - log.debug("Registering JaxbAnnotationModule: {}", module); - objectMapper.registerModule(module); - } - - if (useList) { - setCollectionType(ArrayList.class); - } - if (include != null) { - JsonInclude.Include inc = getCamelContext().getTypeConverter() - .mandatoryConvertTo(JsonInclude.Include.class, include); - objectMapper.setSerializationInclusion(inc); - } - if (prettyPrint) { - objectMapper.enable(SerializationFeature.INDENT_OUTPUT); - } - - if (enableFeatures != null) { - Iterator<?> it = ObjectHelper.createIterator(enableFeatures); - while (it.hasNext()) { - String enable = it.next().toString(); - // it can be different kind - SerializationFeature sf = getCamelContext().getTypeConverter() - .tryConvertTo(SerializationFeature.class, enable); - if (sf != null) { - objectMapper.enable(sf); - continue; - } - DeserializationFeature df = getCamelContext().getTypeConverter() - .tryConvertTo(DeserializationFeature.class, enable); - if (df != null) { - objectMapper.enable(df); - continue; - } - MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, enable); - if (mf != null) { - objectMapper.enable(mf); - continue; - } - throw new IllegalArgumentException("Enable feature: " + enable - + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]"); - } - } - if (disableFeatures != null) { - Iterator<?> it = ObjectHelper.createIterator(disableFeatures); - while (it.hasNext()) { - String disable = it.next().toString(); - // it can be different kind - SerializationFeature sf = getCamelContext().getTypeConverter() - .tryConvertTo(SerializationFeature.class, disable); - if (sf != null) { - objectMapper.disable(sf); - continue; - } - DeserializationFeature df = getCamelContext().getTypeConverter() - .tryConvertTo(DeserializationFeature.class, disable); - if (df != null) { - objectMapper.disable(df); - continue; - } - MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, disable); - if (mf != null) { - objectMapper.disable(mf); - continue; - } - throw new IllegalArgumentException("Disable feature: " + disable - + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]"); - } - } - - if (modules != null) { - for (Module module : modules) { - log.debug("Registering module: {}", module); - objectMapper.registerModules(module); - } - } - if (moduleClassNames != null) { - Iterable<?> it = ObjectHelper.createIterable(moduleClassNames); - for (Object o : it) { - String name = o.toString(); - Class<Module> clazz = camelContext.getClassResolver().resolveMandatoryClass(name, Module.class); - Module module = camelContext.getInjector().newInstance(clazz); - log.debug("Registering module: {} -> {}", name, module); - objectMapper.registerModule(module); - } - } - if (moduleRefs != null) { - Iterable<?> it = ObjectHelper.createIterable(moduleRefs); - for (Object o : it) { - String name = o.toString(); - if (name.startsWith("#")) { - name = name.substring(1); - } - Module module = CamelContextHelper.mandatoryLookup(camelContext, name, Module.class); - log.debug("Registering module: {} -> {}", name, module); - objectMapper.registerModule(module); - } - } - if (org.apache.camel.util.ObjectHelper.isNotEmpty(timezone)) { - log.debug("Setting timezone to Object Mapper: {}", timezone); - objectMapper.setTimeZone(timezone); - } - } - } - - @Override - protected void doStop() throws Exception { - // noop - } + private CamelContext camelContext; + private ObjectMapper objectMapper; + private boolean useDefaultObjectMapper = true; + private Class<? extends Collection> collectionType; + private List<Module> modules; + private String moduleClassNames; + private String moduleRefs; + private Class<?> unmarshalType; + private Class<?> jsonView; + private String include; + private boolean prettyPrint; + private boolean allowJmsType; + private boolean useList; + private boolean enableJaxbAnnotationModule; + private String enableFeatures; + private String disableFeatures; + private boolean enableJacksonTypeConverter; + private boolean allowUnmarshallType; + private boolean contentTypeHeader = true; + private TimeZone timezone; + private boolean autoDiscoverObjectMapper; + + /** + * Use the default Jackson {@link ObjectMapper} and {@link Object} + */ + public JacksonDataFormat() { + this(Object.class); + } + + /** + * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal + * type + * + * @param unmarshalType the custom unmarshal type + */ + public JacksonDataFormat(Class<?> unmarshalType) { + this(unmarshalType, null); + } + + /** + * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal + * type and JSON view + * + * @param unmarshalType the custom unmarshal type + * @param jsonView marker class to specify properties to be included during + * marshalling. See also + * http://wiki.fasterxml.com/JacksonJsonViews + */ + public JacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView) { + this(unmarshalType, jsonView, true); + } + + /** + * Use the default Jackson {@link ObjectMapper} and with a custom unmarshal + * type and JSON view + * + * @param unmarshalType the custom unmarshal type + * @param jsonView marker class to specify properties to be included during + * marshalling. See also + * http://wiki.fasterxml.com/JacksonJsonViews + * @param enableJaxbAnnotationModule if it is true, will enable the + * JaxbAnnotationModule. + */ + public JacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView, boolean enableJaxbAnnotationModule) { + this.unmarshalType = unmarshalType; + this.jsonView = jsonView; + this.enableJaxbAnnotationModule = enableJaxbAnnotationModule; + } + + /** + * Use a custom Jackson mapper and and unmarshal type + * + * @param mapper the custom mapper + * @param unmarshalType the custom unmarshal type + */ + public JacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType) { + this(mapper, unmarshalType, null); + } + + /** + * Use a custom Jackson mapper, unmarshal type and JSON view + * + * @param mapper the custom mapper + * @param unmarshalType the custom unmarshal type + * @param jsonView marker class to specify properties to be included during + * marshalling. See also + * http://wiki.fasterxml.com/JacksonJsonViews + */ + public JacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType, Class<?> jsonView) { + this.objectMapper = mapper; + this.unmarshalType = unmarshalType; + this.jsonView = jsonView; + } + + @Override + public String getDataFormatName() { + return "json-jackson"; + } + + @Override + public CamelContext getCamelContext() { + return camelContext; + } + + @Override + public void setCamelContext(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { + this.objectMapper.writerWithView(jsonView).writeValue(stream, graph); + + if (contentTypeHeader) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } + } + } + + @Override + public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { + + // is there a header with the unmarshal type? + Class<?> clazz = unmarshalType; + String type = null; + if (allowUnmarshallType) { + type = exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class); + } + if (type == null && isAllowJmsType()) { + type = exchange.getIn().getHeader("JMSType", String.class); + } + if (type != null) { + clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type); + } + if (collectionType != null) { + CollectionType collType = objectMapper.getTypeFactory().constructCollectionType(collectionType, clazz); + return this.objectMapper.readValue(stream, collType); + } else { + return this.objectMapper.readValue(stream, clazz); + } + } + + // Properties + // ------------------------------------------------------------------------- + + public ObjectMapper getObjectMapper() { + return this.objectMapper; + } + + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + public boolean isUseDefaultObjectMapper() { + return useDefaultObjectMapper; + } + + public void setUseDefaultObjectMapper(boolean useDefaultObjectMapper) { + this.useDefaultObjectMapper = useDefaultObjectMapper; + } + + public Class<?> getUnmarshalType() { + return this.unmarshalType; + } + + public void setUnmarshalType(Class<?> unmarshalType) { + this.unmarshalType = unmarshalType; + } + + public Class<? extends Collection> getCollectionType() { + return collectionType; + } + + public void setCollectionType(Class<? extends Collection> collectionType) { + this.collectionType = collectionType; + } + + public Class<?> getJsonView() { + return jsonView; + } + + public void setJsonView(Class<?> jsonView) { + this.jsonView = jsonView; + } + + public String getInclude() { + return include; + } + + public void setInclude(String include) { + this.include = include; + } + + public boolean isAllowJmsType() { + return allowJmsType; + } + + public boolean isPrettyPrint() { + return prettyPrint; + } + + public void setPrettyPrint(boolean prettyPrint) { + this.prettyPrint = prettyPrint; + } + + public boolean isUseList() { + return useList; + } + + public void setUseList(boolean useList) { + this.useList = useList; + } + + public boolean isEnableJaxbAnnotationModule() { + return enableJaxbAnnotationModule; + } + + public void setEnableJaxbAnnotationModule(boolean enableJaxbAnnotationModule) { + this.enableJaxbAnnotationModule = enableJaxbAnnotationModule; + } + + public List<Module> getModules() { + return modules; + } + + /** + * To use custom Jackson {@link Module}s + */ + public void setModules(List<Module> modules) { + this.modules = modules; + } + + public String getModuleClassNames() { + return moduleClassNames; + } + + /** + * To use the custom Jackson module + */ + public void addModule(Module module) { + if (this.modules == null) { + this.modules = new ArrayList<>(); + } + this.modules.add(module); + } + + /** + * To use custom Jackson {@link Module}s specified as a String with FQN + * class names. Multiple classes can be separated by comma. + */ + public void setModuleClassNames(String moduleClassNames) { + this.moduleClassNames = moduleClassNames; + } + + public String getModuleRefs() { + return moduleRefs; + } + + /** + * To use custom Jackson modules referred from the Camel registry. Multiple + * modules can be separated by comma. + */ + public void setModuleRefs(String moduleRefs) { + this.moduleRefs = moduleRefs; + } + + /** + * Uses {@link java.util.ArrayList} when unmarshalling. + */ + public void useList() { + setCollectionType(ArrayList.class); + } + + /** + * Uses {@link java.util.HashMap} when unmarshalling. + */ + public void useMap() { + setCollectionType(null); + setUnmarshalType(HashMap.class); + } + + /** + * Allows jackson to use the <tt>JMSType</tt> header as an indicator what + * the classname is for unmarshaling json content to POJO + * <p/> + * By default this option is <tt>false</tt>. + */ + public void setAllowJmsType(boolean allowJmsType) { + this.allowJmsType = allowJmsType; + } + + public boolean isEnableJacksonTypeConverter() { + return enableJacksonTypeConverter; + } + + /** + * If enabled then Jackson is allowed to attempt to be used during Camels + * <a href="https://camel.apache.org/type-converter.html">type converter</a> + * as a {@link org.apache.camel.FallbackConverter} that attempts to convert + * POJOs to/from {@link Map}/{@link List} types. + * <p/> + * This should only be enabled when desired to be used. + */ + public void setEnableJacksonTypeConverter(boolean enableJacksonTypeConverter) { + this.enableJacksonTypeConverter = enableJacksonTypeConverter; + } + + public boolean isAllowUnmarshallType() { + return allowUnmarshallType; + } + + /** + * If enabled then Jackson is allowed to attempt to use the + * CamelJacksonUnmarshalType header during the unmarshalling. + * <p/> + * This should only be enabled when desired to be used. + */ + public void setAllowUnmarshallType(boolean allowJacksonUnmarshallType) { + this.allowUnmarshallType = allowJacksonUnmarshallType; + } + + public boolean isContentTypeHeader() { + return contentTypeHeader; + } + + /** + * If enabled then Jackson will set the Content-Type header to + * <tt>application/json</tt> when marshalling. + */ + public void setContentTypeHeader(boolean contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + + public TimeZone getTimezone() { + return timezone; + } + + /** + * If set then Jackson will use the Timezone when marshalling/unmarshalling. + */ + public void setTimezone(TimeZone timezone) { + this.timezone = timezone; + } + + public boolean isAutoDiscoverObjectMapper() { + return autoDiscoverObjectMapper; + } + + /** + * If set to true then Jackson will lookup for an objectMapper into the + * registry + */ + public void setAutoDiscoverObjectMapper(boolean autoDiscoverObjectMapper) { + this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; + } + + public String getEnableFeatures() { + return enableFeatures; + } + + /** + * Set of features to enable on the Jackson {@link ObjectMapper}. The + * features should be a name that matches a enum from + * {@link SerializationFeature}, {@link DeserializationFeature}, or + * {@link MapperFeature}. + */ + public void setEnableFeatures(String enableFeatures) { + this.enableFeatures = enableFeatures; + } + + public String getDisableFeatures() { + return disableFeatures; + } + + /** + * Set of features to disable on the Jackson {@link ObjectMapper}. The + * features should be a name that matches a enum from + * {@link SerializationFeature}, {@link DeserializationFeature}, or + * {@link MapperFeature}. + */ + public void setDisableFeatures(String disableFeatures) { + this.disableFeatures = disableFeatures; + } + + public void enableFeature(SerializationFeature feature) { + if (enableFeatures == null) { + enableFeatures = feature.name(); + } else { + enableFeatures += "," + feature.name(); + } + } + + public void enableFeature(DeserializationFeature feature) { + if (enableFeatures == null) { + enableFeatures = feature.name(); + } else { + enableFeatures += "," + feature.name(); + } + } + + public void enableFeature(MapperFeature feature) { + if (enableFeatures == null) { + enableFeatures = feature.name(); + } else { + enableFeatures += "," + feature.name(); + } + } + + public void disableFeature(SerializationFeature feature) { + if (disableFeatures == null) { + disableFeatures = feature.name(); + } else { + disableFeatures += "," + feature.name(); + } + } + + public void disableFeature(DeserializationFeature feature) { + if (disableFeatures == null) { + disableFeatures = feature.name(); + } else { + disableFeatures += "," + feature.name(); + } + } + + public void disableFeature(MapperFeature feature) { + if (disableFeatures == null) { + disableFeatures = feature.name(); + } else { + disableFeatures += "," + feature.name(); + } + } + + @Override + protected void doStart() throws Exception { + boolean objectMapperFoundRegistry = false; + if (objectMapper == null) { + // lookup if there is a single default mapper we can use + if (useDefaultObjectMapper && camelContext != null) { + if (isAutoDiscoverObjectMapper()) { + Set<ObjectMapper> set = camelContext.getRegistry().findByType(ObjectMapper.class); + if (set.size() == 1) { + objectMapper = set.iterator().next(); + log.info("Found single ObjectMapper in Registry to use: {}", objectMapper); + objectMapperFoundRegistry = true; + } else if (set.size() > 1) { + log.debug("Found {} ObjectMapper in Registry cannot use as default as there are more than one instance.", set.size()); + } + } else { + log.warn("The option autoDiscoverObjectMapper is set to false, Camel won't search in the registry"); + } + } + if (objectMapper == null) { + objectMapper = new ObjectMapper(); + log.debug("Creating new ObjectMapper to use: {}", objectMapper); + } + } + + if (!objectMapperFoundRegistry) { + if (enableJaxbAnnotationModule) { + // Enables JAXB processing + JaxbAnnotationModule module = new JaxbAnnotationModule(); + log.debug("Registering JaxbAnnotationModule: {}", module); + objectMapper.registerModule(module); + } + + if (useList) { + setCollectionType(ArrayList.class); + } + if (include != null) { + JsonInclude.Include inc = getCamelContext().getTypeConverter().mandatoryConvertTo(JsonInclude.Include.class, include); + objectMapper.setSerializationInclusion(inc); + } + if (prettyPrint) { + objectMapper.enable(SerializationFeature.INDENT_OUTPUT); + } + + if (enableFeatures != null) { + Iterator<?> it = ObjectHelper.createIterator(enableFeatures); + while (it.hasNext()) { + String enable = it.next().toString(); + // it can be different kind + SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, enable); + if (sf != null) { + objectMapper.enable(sf); + continue; + } + DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, enable); + if (df != null) { + objectMapper.enable(df); + continue; + } + MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, enable); + if (mf != null) { + objectMapper.enable(mf); + continue; + } + throw new IllegalArgumentException("Enable feature: " + enable + + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]"); + } + } + if (disableFeatures != null) { + Iterator<?> it = ObjectHelper.createIterator(disableFeatures); + while (it.hasNext()) { + String disable = it.next().toString(); + // it can be different kind + SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, disable); + if (sf != null) { + objectMapper.disable(sf); + continue; + } + DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, disable); + if (df != null) { + objectMapper.disable(df); + continue; + } + MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, disable); + if (mf != null) { + objectMapper.disable(mf); + continue; + } + throw new IllegalArgumentException("Disable feature: " + disable + + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]"); + } + } + + if (modules != null) { + for (Module module : modules) { + log.debug("Registering module: {}", module); + objectMapper.registerModules(module); + } + } + if (moduleClassNames != null) { + Iterable<?> it = ObjectHelper.createIterable(moduleClassNames); + for (Object o : it) { + String name = o.toString(); + Class<Module> clazz = camelContext.getClassResolver().resolveMandatoryClass(name, Module.class); + Module module = camelContext.getInjector().newInstance(clazz); + log.debug("Registering module: {} -> {}", name, module); + objectMapper.registerModule(module); + } + } + if (moduleRefs != null) { + Iterable<?> it = ObjectHelper.createIterable(moduleRefs); + for (Object o : it) { + String name = o.toString(); + if (name.startsWith("#")) { + name = name.substring(1); + } + Module module = CamelContextHelper.mandatoryLookup(camelContext, name, Module.class); + log.debug("Registering module: {} -> {}", name, module); + objectMapper.registerModule(module); + } + } + if (org.apache.camel.util.ObjectHelper.isNotEmpty(timezone)) { + log.debug("Setting timezone to Object Mapper: {}", timezone); + objectMapper.setTimeZone(timezone); + } + } + } + + @Override + protected void doStop() throws Exception { + // noop + } } diff --git a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java index 85bac9e..b3e015a 100644 --- a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java +++ b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java @@ -19,7 +19,8 @@ package org.apache.camel.component.jackson; import com.fasterxml.jackson.databind.ObjectMapper; /** - * A {@link org.apache.camel.component.jackson.JacksonDataFormat} that is using a list + * A {@link org.apache.camel.component.jackson.JacksonDataFormat} that is using + * a list */ public class ListJacksonDataFormat extends JacksonDataFormat { @@ -36,7 +37,7 @@ public class ListJacksonDataFormat extends JacksonDataFormat { super(unmarshalType, jsonView); useList(); } - + public ListJacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView, boolean enableJaxbAnnotationModule) { super(unmarshalType, jsonView, enableJaxbAnnotationModule); useList(); diff --git a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/converter/JacksonTypeConverters.java b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/converter/JacksonTypeConverters.java index fe90ec5..f906d11 100644 --- a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/converter/JacksonTypeConverters.java +++ b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/converter/JacksonTypeConverters.java @@ -31,16 +31,19 @@ import org.apache.camel.spi.Registry; import org.apache.camel.spi.TypeConverterRegistry; /** - * Jackson {@link org.apache.camel.TypeConverter} that allows converting json to/from POJOs and other types. - * <br/> + * Jackson {@link org.apache.camel.TypeConverter} that allows converting json + * to/from POJOs and other types. <br/> * This implementation uses a fallback converter. * <p/> * The converter is disabled by default. To enable then set the property - * {@link JacksonConstants#ENABLE_TYPE_CONVERTER} to <tt>true</tt> on {@link CamelContext#getGlobalOptions()}. - * <br/> - * The option {@link JacksonConstants#TYPE_CONVERTER_TO_POJO} can be used to allow converting to POJO types. By - * default the converter only attempts to convert to primitive types such as String and numbers. To convert to any kind, then - * enable this by setting {@link JacksonConstants#TYPE_CONVERTER_TO_POJO} to <tt>true</tt> on {@link CamelContext#getGlobalOptions()}. + * {@link JacksonConstants#ENABLE_TYPE_CONVERTER} to <tt>true</tt> on + * {@link CamelContext#getGlobalOptions()}. <br/> + * The option {@link JacksonConstants#TYPE_CONVERTER_TO_POJO} can be used to + * allow converting to POJO types. By default the converter only attempts to + * convert to primitive types such as String and numbers. To convert to any + * kind, then enable this by setting + * {@link JacksonConstants#TYPE_CONVERTER_TO_POJO} to <tt>true</tt> on + * {@link CamelContext#getGlobalOptions()}. */ @Converter(generateLoader = true) public final class JacksonTypeConverters { @@ -52,7 +55,8 @@ public final class JacksonTypeConverters { public JacksonTypeConverters() { defaultMapper = new ObjectMapper(); - // Enables JAXB processing so we can easily convert JAXB annotated pojos also + // Enables JAXB processing so we can easily convert JAXB annotated pojos + // also JaxbAnnotationModule module = new JaxbAnnotationModule(); defaultMapper.registerModule(module); } @@ -90,9 +94,11 @@ public final class JacksonTypeConverters { if (exchange != null) { ObjectMapper mapper = resolveObjectMapper(exchange.getContext().getRegistry()); - // favor use write/read operations as they are higher level than the convertValue + // favor use write/read operations as they are higher level than the + // convertValue - // if we want to convert to a String or byte[] then use write operation + // if we want to convert to a String or byte[] then use write + // operation if (String.class.isAssignableFrom(type)) { String out = mapper.writeValueAsString(value); return type.cast(out); @@ -100,17 +106,18 @@ public final class JacksonTypeConverters { byte[] out = mapper.writeValueAsBytes(value); return type.cast(out); } else if (mapper.canSerialize(type) && !Enum.class.isAssignableFrom(type)) { - // if the source value type is readable by the mapper then use its read operation + // if the source value type is readable by the mapper then use + // its read operation if (String.class.isAssignableFrom(value.getClass())) { - return mapper.readValue((String) value, type); + return mapper.readValue((String)value, type); } else if (byte[].class.isAssignableFrom(value.getClass())) { - return mapper.readValue((byte[]) value, type); + return mapper.readValue((byte[])value, type); } else if (File.class.isAssignableFrom(value.getClass())) { - return mapper.readValue((File) value, type); + return mapper.readValue((File)value, type); } else if (InputStream.class.isAssignableFrom(value.getClass())) { - return mapper.readValue((InputStream) value, type); + return mapper.readValue((InputStream)value, type); } else if (Reader.class.isAssignableFrom(value.getClass())) { - return mapper.readValue((Reader) value, type); + return mapper.readValue((Reader)value, type); } else { // fallback to generic convert value return mapper.convertValue(value, type); @@ -123,14 +130,13 @@ public final class JacksonTypeConverters { } /** - * Whether the type is NOT a pojo type but only a set of simple types such as String and numbers. + * Whether the type is NOT a pojo type but only a set of simple types such + * as String and numbers. */ private static boolean isNotPojoType(Class<?> type) { boolean isString = String.class.isAssignableFrom(type); - boolean isNumber = Number.class.isAssignableFrom(type) - || int.class.isAssignableFrom(type) || long.class.isAssignableFrom(type) - || short.class.isAssignableFrom(type) || char.class.isAssignableFrom(type) - || float.class.isAssignableFrom(type) || double.class.isAssignableFrom(type); + boolean isNumber = Number.class.isAssignableFrom(type) || int.class.isAssignableFrom(type) || long.class.isAssignableFrom(type) || short.class.isAssignableFrom(type) + || char.class.isAssignableFrom(type) || float.class.isAssignableFrom(type) || double.class.isAssignableFrom(type); return isString || isNumber; } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonConcurrentTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonConcurrentTest.java index 0803c86..2e0124c 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonConcurrentTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonConcurrentTest.java @@ -63,14 +63,9 @@ public class JacksonConcurrentTest extends CamelTestSupport { protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { - from("direct:start"). - marshal().json(JsonLibrary.Jackson). - to("log:marshalled"). - to("direct:marshalled"); + from("direct:start").marshal().json(JsonLibrary.Jackson).to("log:marshalled").to("direct:marshalled"); - from("direct:marshalled"). - unmarshal().json(JsonLibrary.Jackson, TestPojo.class). - to("mock:result"); + from("direct:marshalled").unmarshal().json(JsonLibrary.Jackson, TestPojo.class).to("mock:result"); } }; } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonDataFormatTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonDataFormatTest.java index 7453c09..08af0d9 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonDataFormatTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonDataFormatTest.java @@ -54,4 +54,4 @@ public class JacksonDataFormatTest { assertEquals(expected, unmarshalled); } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java index 92aae09..09af454 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java @@ -39,4 +39,4 @@ public class JacksonJsonDataFormatTest extends JacksonMarshalTest { }; } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalDateTimezoneTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalDateTimezoneTest.java index 308e995..2805547 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalDateTimezoneTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalDateTimezoneTest.java @@ -25,7 +25,6 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; - public class JacksonMarshalDateTimezoneTest extends CamelTestSupport { @Test @@ -38,7 +37,7 @@ public class JacksonMarshalDateTimezoneTest extends CamelTestSupport { Object marshalled = template.requestBody("direct:in", in.getTime()); String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); assertEquals("1493139610000", marshalledAsString); - + mock.expectedMessageCount(1); mock.assertIsSatisfied(); diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java index 75deece..0544f45 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java @@ -40,9 +40,9 @@ public class JacksonMarshalUnmarshalListTest extends CamelTestSupport { assertNotNull(list); assertEquals(2, list.size()); - TestPojo pojo = (TestPojo) list.get(0); + TestPojo pojo = (TestPojo)list.get(0); assertEquals("Camel", pojo.getName()); - pojo = (TestPojo) list.get(1); + pojo = (TestPojo)list.get(1); assertEquals("World", pojo.getName()); } @@ -61,7 +61,7 @@ public class JacksonMarshalUnmarshalListTest extends CamelTestSupport { assertNotNull(list); assertEquals(1, list.size()); - TestPojo pojo = (TestPojo) list.get(0); + TestPojo pojo = (TestPojo)list.get(0); assertEquals("Camel", pojo.getName()); } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNotUseDefaultObjectMapperTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNotUseDefaultObjectMapperTest.java index 771c0df..d7fc992 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNotUseDefaultObjectMapperTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonNotUseDefaultObjectMapperTest.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.camel.component.jackson; + import java.util.HashMap; import java.util.Map; @@ -30,7 +31,7 @@ import org.junit.Test; public class JacksonNotUseDefaultObjectMapperTest extends CamelTestSupport { private JacksonDataFormat df = new JacksonDataFormat(); - + @BindToRegistry("myMapper") private ObjectMapper objectMapper = new ObjectMapper(); diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectListSplitTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectListSplitTest.java index a558863..fbb4e9a 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectListSplitTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectListSplitTest.java @@ -36,14 +36,15 @@ public class JacksonObjectListSplitTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - // you can specify the pojo class type for unmarshal the jason file + // you can specify the pojo class type for unmarshal the jason + // file JacksonDataFormat format = new JacksonDataFormat(DummyObject.class); format.useList(); from("direct:start").unmarshal(format).split(body()).to("mock:result"); } }; } - + public static class DummyObject { private String dummy; @@ -60,4 +61,4 @@ public class JacksonObjectListSplitTest extends CamelTestSupport { } } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectMapperRegistryTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectMapperRegistryTest.java index fc106ba..d25521f 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectMapperRegistryTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonObjectMapperRegistryTest.java @@ -32,7 +32,7 @@ import org.junit.Test; public class JacksonObjectMapperRegistryTest extends CamelTestSupport { private JacksonDataFormat df; - + @BindToRegistry("myMapper") private ObjectMapper objectMapper = new ObjectMapper(); @@ -62,9 +62,9 @@ public class JacksonObjectMapperRegistryTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - df = new JacksonDataFormat(); - df.setAutoDiscoverObjectMapper(true); - + df = new JacksonDataFormat(); + df.setAutoDiscoverObjectMapper(true); + from("direct:in").marshal(df); from("direct:back").unmarshal(df).to("mock:reverse"); } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java index 9586439..7923907 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java @@ -41,9 +41,9 @@ public class SpringJacksonMarshalUnmarshalListTest extends CamelSpringTestSuppor assertNotNull(list); assertEquals(2, list.size()); - TestPojo pojo = (TestPojo) list.get(0); + TestPojo pojo = (TestPojo)list.get(0); assertEquals("Camel", pojo.getName()); - pojo = (TestPojo) list.get(1); + pojo = (TestPojo)list.get(1); assertEquals("World", pojo.getName()); } @@ -62,7 +62,7 @@ public class SpringJacksonMarshalUnmarshalListTest extends CamelSpringTestSuppor assertNotNull(list); assertEquals(1, list.size()); - TestPojo pojo = (TestPojo) list.get(0); + TestPojo pojo = (TestPojo)list.get(0); assertEquals("Camel", pojo.getName()); } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java index bf22c7d..62dd876 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java @@ -51,10 +51,10 @@ public class SpringJacksonObjectMapperRegistryTest extends CamelSpringTestSuppor mock.assertIsSatisfied(); - MyJsonObjectMapper mapper = (MyJsonObjectMapper) context.getRegistry().lookupByName("myJsonObjectMapper"); + MyJsonObjectMapper mapper = (MyJsonObjectMapper)context.getRegistry().lookupByName("myJsonObjectMapper"); assertNotNull(mapper); - JacksonDataFormat df = (JacksonDataFormat) DataFormatReifier.getDataFormat(context, null, "jack"); + JacksonDataFormat df = (JacksonDataFormat)DataFormatReifier.getDataFormat(context, null, "jack"); assertNotNull(df); assertSame(mapper, df.getObjectMapper()); } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestJAXBPojo.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestJAXBPojo.java index b9d7b14..a8867da 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestJAXBPojo.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestJAXBPojo.java @@ -35,7 +35,7 @@ public class TestJAXBPojo { @Override public boolean equals(Object obj) { - return this.name.equals(((TestJAXBPojo) obj).getName()); + return this.name.equals(((TestJAXBPojo)obj).getName()); } @Override @@ -47,4 +47,4 @@ public class TestJAXBPojo { public String toString() { return "TestJAXBPojo[" + name + "]"; } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestOtherPojo.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestOtherPojo.java index 7f66153..d2d43e3 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestOtherPojo.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestOtherPojo.java @@ -37,4 +37,4 @@ public class TestOtherPojo { this.country = country; } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojo.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojo.java index 6382bf7..ba47dce 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojo.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojo.java @@ -30,7 +30,7 @@ public class TestPojo { @Override public boolean equals(Object obj) { - return this.name.equals(((TestPojo) obj).getName()); + return this.name.equals(((TestPojo)obj).getName()); } @Override @@ -42,4 +42,4 @@ public class TestPojo { public String toString() { return "TestPojo[" + name + "]"; } -} \ No newline at end of file +} diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java index 7fb775d..dc6191d 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonView; public class TestPojoView { - //START SNIPPET: jsonview + // START SNIPPET: jsonview @JsonView(Views.Age.class) private int age = 30; @@ -28,7 +28,7 @@ public class TestPojoView { @JsonView(Views.Weight.class) private int weight = 70; - //END SNIPPET: jsonview + // END SNIPPET: jsonview public int getAge() { return age; @@ -63,7 +63,7 @@ public class TestPojoView { return false; } - TestPojoView that = (TestPojoView) o; + TestPojoView that = (TestPojoView)o; if (age != that.age) { return false; diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/Views.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/Views.java index dcb3387..4c238ac 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/Views.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/Views.java @@ -19,7 +19,10 @@ package org.apache.camel.component.jackson; //START SNIPPET: marker public class Views { - static class Age { } - static class Weight { } + static class Age { + } + + static class Weight { + } } //END SNIPPET: marker diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java index cbcef4a..84e1a29 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java @@ -27,7 +27,8 @@ public class JacksonConversionsPojoTest extends CamelTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - // enable jackson type converter by setting this property on CamelContext + // enable jackson type converter by setting this property on + // CamelContext context.getGlobalOptions().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true"); context.getGlobalOptions().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true"); return context; @@ -40,7 +41,7 @@ public class JacksonConversionsPojoTest extends CamelTestSupport { order.setCustomerName("Acme"); order.setPartName("Camel"); - String json = (String) template.requestBody("direct:test", order); + String json = (String)template.requestBody("direct:test", order); assertEquals("{\"id\":0,\"partName\":\"Camel\",\"amount\":1,\"customerName\":\"Acme\"}", json); } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsSimpleTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsSimpleTest.java index 219eb8e..a182099 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsSimpleTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsSimpleTest.java @@ -37,7 +37,8 @@ public class JacksonConversionsSimpleTest extends CamelTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - // enable jackson type converter by setting this property on CamelContext + // enable jackson type converter by setting this property on + // CamelContext context.getGlobalOptions().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true"); return context; } diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsTest.java index f141c2e..3271b17 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsTest.java @@ -31,7 +31,8 @@ public class JacksonConversionsTest extends CamelTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - // enable jackson type converter by setting this property on CamelContext + // enable jackson type converter by setting this property on + // CamelContext context.getGlobalOptions().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true"); return context; } @@ -42,7 +43,7 @@ public class JacksonConversionsTest extends CamelTestSupport { Map<String, String> pojoAsMap = new HashMap<>(); pojoAsMap.put("name", name); - TestPojo testPojo = (TestPojo) template.requestBody("direct:test", pojoAsMap); + TestPojo testPojo = (TestPojo)template.requestBody("direct:test", pojoAsMap); assertEquals(name, testPojo.getName()); }