Repository: camel
Updated Branches:
  refs/heads/master b0dbc07b0 -> 02826d57e


CAMEL-8389: camel-jackson - Allow to configure jackson object mapper from XML 
DSL


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2777d9b0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2777d9b0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2777d9b0

Branch: refs/heads/master
Commit: 2777d9b0e44b24c46fd88841bbc9d27a4ad6df3a
Parents: b0dbc07
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun Feb 22 09:27:15 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun Feb 22 09:27:15 2015 +0100

----------------------------------------------------------------------
 .../camel/model/dataformat/JsonDataFormat.java  |  40 +++++++
 .../component/jackson/JacksonDataFormat.java    | 117 ++++++++++++++++++-
 2 files changed, 156 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2777d9b0/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
 
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
index 50e61f0..30f9fe0 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
@@ -16,9 +16,11 @@
  */
 package org.apache.camel.model.dataformat;
 
+import java.util.Set;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
@@ -64,6 +66,10 @@ public class JsonDataFormat extends DataFormatDefinition {
     private String moduleClassNames;
     @XmlAttribute
     private String moduleRefs;
+    @XmlElement
+    private Set<String> enableFeatures;
+    @XmlElement
+    private Set<String> disableFeatures;
 
     public JsonDataFormat() {
         super("json");
@@ -217,6 +223,34 @@ public class JsonDataFormat extends DataFormatDefinition {
         this.moduleRefs = moduleRefs;
     }
 
+    public Set<String> getEnableFeatures() {
+        return enableFeatures;
+    }
+
+    /**
+     * Set of features to enable on the Jackson 
<tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
+     * <p/>
+     * The features should be a name that matches a enum from 
<tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
+     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or 
<tt>com.fasterxml.jackson.databind.MapperFeature</tt>
+     */
+    public void setEnableFeatures(Set<String> enableFeatures) {
+        this.enableFeatures = enableFeatures;
+    }
+
+    public Set<String> getDisableFeatures() {
+        return disableFeatures;
+    }
+
+    /**
+     * Set of features to disable on the Jackson 
<tt>com.fasterxml.jackson.databind.ObjectMapper</tt>.
+     * <p/>
+     * The features should be a name that matches a enum from 
<tt>com.fasterxml.jackson.databind.SerializationFeature</tt>,
+     * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or 
<tt>com.fasterxml.jackson.databind.MapperFeature</tt>
+     */
+    public void setDisableFeatures(Set<String> disableFeatures) {
+        this.disableFeatures = disableFeatures;
+    }
+
     @Override
     public String getDataFormatName() {
         // json data format is special as the name can be from different 
bundles
@@ -283,6 +317,12 @@ public class JsonDataFormat extends DataFormatDefinition {
         if (moduleRefs != null) {
             setProperty(camelContext, dataFormat, "moduleRefs", moduleRefs);
         }
+        if (enableFeatures != null) {
+            setProperty(camelContext, dataFormat, "enableFeatures", 
enableFeatures);
+        }
+        if (disableFeatures != null) {
+            setProperty(camelContext, dataFormat, "disableFeatures", 
disableFeatures);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2777d9b0/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
----------------------------------------------------------------------
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 015ee52..ef1016f 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
@@ -21,10 +21,14 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
 import com.fasterxml.jackson.databind.Module;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
@@ -61,6 +65,8 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat, Cam
     private boolean allowJmsType;
     private boolean useList;
     private boolean enableJaxbAnnotationModule;
+    private Set<String> enableFeatures;
+    private Set<String> disableFeatures;
 
     /**
      * Use the default Jackson {@link ObjectMapper} and {@link Map}
@@ -288,6 +294,72 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat, Cam
         this.allowJmsType = allowJmsType;
     }
 
+    public Set<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(Set<String> enableFeatures) {
+        this.enableFeatures = enableFeatures;
+    }
+
+    public Set<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(Set<String> disableFeatures) {
+        this.disableFeatures = disableFeatures;
+    }
+
+    public void enableFeature(SerializationFeature feature) {
+        if (enableFeatures == null) {
+            enableFeatures = new HashSet<String>();
+        }
+        enableFeatures.add(feature.name());
+    }
+
+    public void enableFeature(DeserializationFeature feature) {
+        if (enableFeatures == null) {
+            enableFeatures = new HashSet<String>();
+        }
+        enableFeatures.add(feature.name());
+    }
+
+    public void enableFeature(MapperFeature feature) {
+        if (enableFeatures == null) {
+            enableFeatures = new HashSet<String>();
+        }
+        enableFeatures.add(feature.name());
+    }
+
+    public void disableFeature(SerializationFeature feature) {
+        if (disableFeatures == null) {
+            disableFeatures = new HashSet<String>();
+        }
+        disableFeatures.add(feature.name());
+    }
+
+    public void disableFeature(DeserializationFeature feature) {
+        if (disableFeatures == null) {
+            disableFeatures = new HashSet<String>();
+        }
+        disableFeatures.add(feature.name());
+    }
+
+    public void disableFeature(MapperFeature feature) {
+        if (disableFeatures == null) {
+            disableFeatures = new HashSet<String>();
+        }
+        disableFeatures.add(feature.name());
+    }
+
     @Override
     protected void doStart() throws Exception {
         
@@ -302,13 +374,56 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat, Cam
             setCollectionType(ArrayList.class);
         }
         if (include != null) {
-            JsonInclude.Include inc = JsonInclude.Include.valueOf(include);
+            JsonInclude.Include inc = 
getCamelContext().getTypeConverter().mandatoryConvertTo(JsonInclude.Include.class,
 include);
             objectMapper.setSerializationInclusion(inc);
         }
         if (prettyPrint) {
             objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
         }
 
+        if (enableFeatures != null) {
+            for (String enable : enableFeatures) {
+                // 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) {
+            for (String disable : disableFeatures) {
+                // 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.info("Registering module: {}", module);

Reply via email to