ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [11/50] [abbrv] ignite git commit: JSON: workaround for false cycle detection in case of spring exceptions.
Date Mon, 20 Jun 2016 02:58:34 GMT
JSON: workaround for false cycle detection in case of spring exceptions.


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

Branch: refs/heads/ignite-3262
Commit: cba61d785e3cea110b19a0f34eee4907a1ab5a79
Parents: 2cf3241
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Fri Jun 3 14:06:21 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri Jun 3 14:06:21 2016 +0700

----------------------------------------------------------------------
 .../protocols/http/jetty/GridJettyJsonConfig.java   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/cba61d78/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyJsonConfig.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyJsonConfig.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyJsonConfig.java
index b85d01e..9e1532a 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyJsonConfig.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyJsonConfig.java
@@ -205,16 +205,20 @@ class GridJettyJsonConfig extends JsonConfig {
     };
 
     /**
-     * Helper class for simple to-string conversion for {@link UUID}.
+     * Workaround for false cycle detection in Spring exceptions.
+     *
+     * Cycle detection of json-lib is quite primitive.
+     * If some bean has more than one reference to same object false cycle will be detected.
      */
-    private static JsonValueProcessor THROWABLE_PROCESSOR = new AbstractJsonValueProcessor()
{
+    private static JsonValueProcessor RUNTIME_EXCEPTION_PROCESSOR = new AbstractJsonValueProcessor()
{
         /** {@inheritDoc} */
         protected Object processBean(Object bean, JsonConfig jsonCfg) {
             if (bean == null)
                 return new JSONObject(true);
 
-            if (bean instanceof Throwable) {
-                Throwable e = (Throwable)bean;
+            if (bean instanceof RuntimeException &&
+                bean.getClass().getCanonicalName().startsWith("org.springframework.")) {
+                RuntimeException e = (RuntimeException)bean;
 
                 final JSONObject ret = new JSONObject();
 
@@ -226,7 +230,7 @@ class GridJettyJsonConfig extends JsonConfig {
                 return ret;
             }
 
-            throw new UnsupportedOperationException("Serialize value to json is not supported:
" + bean);
+            return JSONObject.fromObject(bean, jsonCfg);
         }
     };
 
@@ -244,7 +248,7 @@ class GridJettyJsonConfig extends JsonConfig {
         registerJsonValueProcessor(Date.class, DATE_PROCESSOR);
         registerJsonValueProcessor(java.sql.Date.class, DATE_PROCESSOR);
         registerJsonValueProcessor(HashMap.class, NULL_MAP_PREPROCESSOR);
-        registerJsonValueProcessor(Throwable.class, THROWABLE_PROCESSOR);
+        registerJsonValueProcessor(RuntimeException.class, RUNTIME_EXCEPTION_PROCESSOR);
 
         final LessNamingProcessor lessNamingProcessor = new LessNamingProcessor();
 


Mime
View raw message