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

heneveld 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 712d17fd37 forgive entity/adjunct references in JSON deserialization 
(sensor conversion)
712d17fd37 is described below

commit 712d17fd373643448c601d259758a6e16a0c82a2
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Dec 2 20:32:37 2022 +0000

    forgive entity/adjunct references in JSON deserialization (sensor 
conversion)
---
 .../core/resolve/jackson/CommonTypesSerialization.java   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
 
b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
index feeb811be4..c5d091b007 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
@@ -233,6 +233,10 @@ public class CommonTypesSerialization {
             public T convertSpecialMapToObject(Map value, JsonParser p, 
DeserializationContext ctxt) throws IOException {
                 return 
ObjectAsStringSerializerAndDeserializer.this.convertSpecialMapToObject(value, 
p, ctxt);
             }
+
+            public T convertStringToObject(String value, JsonParser p, 
DeserializationContext ctxt) throws IOException {
+                return 
ObjectAsStringSerializerAndDeserializer.this.convertStringToObject(value, p, 
ctxt);
+            }
         }
     }
 
@@ -379,7 +383,7 @@ public class CommonTypesSerialization {
             @Override
             protected BrooklynObject newEmptyInstance() {
                 /* context buries the contextual types when called via 
createContextual, because we are a delegate; and has cleared it by the time it 
gets here */
-                if (knownConcreteType !=null) {
+                if (knownConcreteType != null) {
                     return 
BrooklynObjectSerialization.this.newEmptyInstance((Class<BrooklynObject>) 
knownConcreteType.getRawClass());
                 }
                 return super.newEmptyInstance();
@@ -428,6 +432,16 @@ public class CommonTypesSerialization {
 
                 throw new IllegalStateException("Entity instances and other 
Brooklyn objects should be supplied as unique IDs; they cannot be instantiated 
from YAML. If a spec is desired, the type should be known or use 
$brooklyn:entitySpec.");
             }
+
+            @Override public BrooklynObject convertStringToObject(String 
value, JsonParser p, DeserializationContext ctxt) throws IOException {
+                try {
+                    return super.convertStringToObject(value, p, ctxt);
+                } catch (Exception e) {
+                    Exceptions.propagateIfFatal(e);
+                    LOG.warn("Reference to BrooklynObject "+value+" which is 
no longer available; replacing with 'null'");
+                    return null;
+                }
+            }
         }
     }
 

Reply via email to