Repository: brooklyn-server
Updated Branches:
  refs/heads/master 43a8816c8 -> ae57587eb


BasicSpecParameter: fix compatibility of persisted state

Support old-style persisted state, by implementing readResolve()


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1d63e39d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1d63e39d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1d63e39d

Branch: refs/heads/master
Commit: 1d63e39d3569ae9de23747e3e19590f19c67f743
Parents: b8211ed
Author: Aled Sage <aled.s...@gmail.com>
Authored: Wed Mar 23 00:50:41 2016 +0000
Committer: Aled Sage <aled.s...@gmail.com>
Committed: Wed Mar 23 20:29:25 2016 +0000

----------------------------------------------------------------------
 .../apache/brooklyn/core/objs/BasicSpecParameter.java  | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1d63e39d/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java 
b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
index 2bc2346..ea041b2 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
@@ -69,6 +69,19 @@ public class BasicSpecParameter<T> implements 
SpecParameter<T>{
     private final ConfigKey<T> configKey;
     private final AttributeSensor<?> sensor;
 
+    // For backwards compatibility of persisted state.
+    // Automatically called by xstream (which is used under the covers by 
XmlMementoSerializer).
+    // Required for those who have state from a version between
+    // 29th October 2015 and 21st January 2016 (when this class was 
introduced, and then when it was changed).
+    private ConfigKey<T> type;
+    private Object readResolve() {
+        if (type != null && configKey == null) {
+            return new BasicSpecParameter(label, pinned, type, sensor);
+        } else {
+            return this;
+        }
+    }
+    
     @Beta // TBD whether "pinned" stays
     public BasicSpecParameter(String label, boolean pinned, ConfigKey<T> 
config) {
         this(label, pinned, config, null);

Reply via email to