You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/02/26 13:57:11 UTC

[1/2] camel git commit: CAMEL-8399: xstream json should support setMode

Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x f3e870875 -> 6e5a040eb
  refs/heads/master f3374c08c -> 64352d344


CAMEL-8399: xstream json should support setMode


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

Branch: refs/heads/master
Commit: 64352d3449f828f914ae34b6d140254fc05f7512
Parents: f3374c0
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Feb 26 13:57:43 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Feb 26 13:57:43 2015 +0100

----------------------------------------------------------------------
 .../dataformat/xstream/AbstractXStreamWrapper.java | 17 +++++++++--------
 .../camel/dataformat/xstream/JsonDataFormat.java   |  6 +++++-
 .../xstream/SpringXStreamConfigurationTest.xml     |  6 +++---
 3 files changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/64352d34/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
index 7e5a9aa..a3f5fab 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
@@ -84,6 +84,10 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
             xstream = new XStream();
         }
 
+        if (mode != null) {
+            xstream.setMode(getModeFromString(mode));
+        }
+
         try {
             if (this.implicitCollections != null) {
                 for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) {
@@ -116,16 +120,16 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
                     Constructor<Converter> con = null;
                     try {
-                        con = converterClass.getDeclaredConstructor(new Class[] {XStream.class});
+                        con = converterClass.getDeclaredConstructor(new Class[]{XStream.class});
                     } catch (Exception e) {
-                         //swallow as we null check in a moment.
+                        //swallow as we null check in a moment.
                     }
                     if (con != null) {
                         converter = con.newInstance(xstream);
                     } else {
                         converter = converterClass.newInstance();
-                        try { 
-                            Method method = converterClass.getMethod("setXStream", new Class[] {XStream.class});
+                        try {
+                            Method method = converterClass.getMethod("setXStream", new Class[]{XStream.class});
                             if (method != null) {
                                 ObjectHelper.invokeMethod(method, converter, xstream);
                             }
@@ -136,11 +140,8 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
                     xstream.registerConverter(converter);
                 }
-                
-                if (mode != null) {
-                    xstream.setMode(getModeFromString(mode));
-                }
             }
+                
         } catch (Exception e) {
             throw new RuntimeException("Unable to build XStream instance", e);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/64352d34/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
index f78690d..238bef7 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
@@ -55,7 +55,11 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
     @Override
     protected XStream createXStream(ClassResolver resolver) {
         XStream xs = super.createXStream(resolver);
-        xs.setMode(XStream.NO_REFERENCES);
+        if (getMode() != null) {
+            xs.setMode(getModeFromString(getMode()));
+        } else {
+            xs.setMode(XStream.NO_REFERENCES);
+        }
         return xs;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/64352d34/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
index 863b951..a171086 100644
--- a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
+++ b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
@@ -34,7 +34,7 @@
                     <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
                 </converters>
                 <aliases>                     
-					<alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
+					        <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
                 </aliases>
                 <implicitCollections>
                    <class name="org.apache.camel.dataformat.xstream.PurchaseHistory">
@@ -43,12 +43,12 @@
                 </implicitCollections>
             </xstream>
             
-           <xstream id="xstream-json" driver="json" mode="ID_REFERENCES">
+           <xstream id="xstream-json" driver="json">
                 <converters>
                     <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
                 </converters>
                 <aliases>                     
-					<alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
+					        <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
                 </aliases>
                 <implicitCollections>
                    <class name="org.apache.camel.dataformat.xstream.PurchaseHistory">


[2/2] camel git commit: CAMEL-8399: xstream json should support setMode

Posted by da...@apache.org.
CAMEL-8399: xstream json should support setMode


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

Branch: refs/heads/camel-2.14.x
Commit: 6e5a040eb4207139c2a810dfef7d0e5c239bd45f
Parents: f3e8708
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Feb 26 13:57:43 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Feb 26 13:58:09 2015 +0100

----------------------------------------------------------------------
 .../dataformat/xstream/AbstractXStreamWrapper.java | 17 +++++++++--------
 .../camel/dataformat/xstream/JsonDataFormat.java   |  6 +++++-
 .../xstream/SpringXStreamConfigurationTest.xml     |  6 +++---
 3 files changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6e5a040e/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
index 7e5a9aa..a3f5fab 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
@@ -84,6 +84,10 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
             xstream = new XStream();
         }
 
+        if (mode != null) {
+            xstream.setMode(getModeFromString(mode));
+        }
+
         try {
             if (this.implicitCollections != null) {
                 for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) {
@@ -116,16 +120,16 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
                     Constructor<Converter> con = null;
                     try {
-                        con = converterClass.getDeclaredConstructor(new Class[] {XStream.class});
+                        con = converterClass.getDeclaredConstructor(new Class[]{XStream.class});
                     } catch (Exception e) {
-                         //swallow as we null check in a moment.
+                        //swallow as we null check in a moment.
                     }
                     if (con != null) {
                         converter = con.newInstance(xstream);
                     } else {
                         converter = converterClass.newInstance();
-                        try { 
-                            Method method = converterClass.getMethod("setXStream", new Class[] {XStream.class});
+                        try {
+                            Method method = converterClass.getMethod("setXStream", new Class[]{XStream.class});
                             if (method != null) {
                                 ObjectHelper.invokeMethod(method, converter, xstream);
                             }
@@ -136,11 +140,8 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
                     xstream.registerConverter(converter);
                 }
-                
-                if (mode != null) {
-                    xstream.setMode(getModeFromString(mode));
-                }
             }
+                
         } catch (Exception e) {
             throw new RuntimeException("Unable to build XStream instance", e);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/6e5a040e/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
index f78690d..238bef7 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
@@ -55,7 +55,11 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
     @Override
     protected XStream createXStream(ClassResolver resolver) {
         XStream xs = super.createXStream(resolver);
-        xs.setMode(XStream.NO_REFERENCES);
+        if (getMode() != null) {
+            xs.setMode(getModeFromString(getMode()));
+        } else {
+            xs.setMode(XStream.NO_REFERENCES);
+        }
         return xs;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6e5a040e/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
index 863b951..a171086 100644
--- a/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
+++ b/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml
@@ -34,7 +34,7 @@
                     <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
                 </converters>
                 <aliases>                     
-					<alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
+					        <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
                 </aliases>
                 <implicitCollections>
                    <class name="org.apache.camel.dataformat.xstream.PurchaseHistory">
@@ -43,12 +43,12 @@
                 </implicitCollections>
             </xstream>
             
-           <xstream id="xstream-json" driver="json" mode="ID_REFERENCES">
+           <xstream id="xstream-json" driver="json">
                 <converters>
                     <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" />
                 </converters>
                 <aliases>                     
-					<alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
+					        <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" />
                 </aliases>
                 <implicitCollections>
                    <class name="org.apache.camel.dataformat.xstream.PurchaseHistory">