This is an automated email from the ASF dual-hosted git repository.

iuliana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new e29ad66  include deserialization trace when hitting deserialization 
problems
     new 8d25edd  Merge pull request #1172 from 
ahgittin/better-errors-on-serialization-problems
e29ad66 is described below

commit e29ad6656544f921c6b2a66194976d8f4335fe17
Author: Alex Heneveld <[email protected]>
AuthorDate: Tue May 11 21:33:04 2021 +0100

    include deserialization trace when hitting deserialization problems
    
    makes it easier to track down the root cause
---
 .../jackson/BrooklynJacksonSerializationUtils.java  | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BrooklynJacksonSerializationUtils.java
 
b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BrooklynJacksonSerializationUtils.java
index e8fbb2f..10711cc 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BrooklynJacksonSerializationUtils.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BrooklynJacksonSerializationUtils.java
@@ -18,13 +18,16 @@
  */
 package org.apache.brooklyn.core.resolve.jackson;
 
+import com.fasterxml.jackson.core.JsonLocation;
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonToken;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.*;
 import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
+import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
 import com.fasterxml.jackson.databind.module.SimpleModule;
 import com.google.common.reflect.TypeToken;
+import java.io.Closeable;
 import java.io.IOException;
 import java.lang.reflect.Type;
 import java.util.List;
@@ -38,6 +41,7 @@ import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.javalang.Boxing;
+import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -139,6 +143,23 @@ public class BrooklynJacksonSerializationUtils {
         }
 
         @Override
+        public void resolve(DeserializationContext ctxt) throws 
JsonMappingException {
+            try {
+                super.resolve(ctxt);
+            } catch (JsonMappingException e) {
+                // supplying process or cause causes location to appear 
multiple times in message,
+                // so clumsy way to maintain a good message and the 
JsonMappingException type
+                // (though not sure we need to maintain that exception; we 
already lose subtypes
+                // eg InvalidDefinitionException, but nothing seems to mind)
+                throw (JsonMappingException) new JsonMappingException(
+                        null,
+                        (Strings.isBlank(e.getMessage()) ? e.toString() : 
e.getMessage()) +
+                        (handledType()!=null ? ", processing "+handledType() : 
""),
+                        (JsonLocation)null).initCause(e);
+            }
+        }
+
+        @Override
         protected Object deserializeWrapper(JsonParser jp, 
DeserializationContext ctxt, BiFunctionThrowsIoException<JsonParser, 
DeserializationContext, Object> nestedDeserialize) throws IOException {
             String v = jp.getCurrentToken()==JsonToken.VALUE_STRING ? 
jp.getValueAsString() : null;
             try {

Reply via email to