Github user m4rkmckenna commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/593#discussion_r105952999
--- Diff:
core/src/main/java/org/apache/brooklyn/util/core/xstream/ObjectWithDefaultStringImplConverter.java
---
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.util.core.xstream;
+
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.javalang.Boxing;
+
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.ConverterLookup;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * A converter that delegates to {@link
ConverterLookup#lookupConverterForType(Class)}, where
+ * possible. On unmarshalling, if there is no {@code class} attribute then
it assumes that the
+ * type must be a {@link String}.
+ *
+ * This is useful if a class has its field changed from type {@link
String} to {@link Object}.
+ * The old persisted state will look like {@code <mykey>myval</mykey>},
rather than
+ * {@code <mykey class="string">myval</mykey>}.
+ *
+ * Use this converter by annotation the field with
+ * {@code @XStreamConverter(ObjectWithDefaultStringImplConverter.class)}.
One must also call
+ * {@code xstream.processAnnotations(MyClazz.class)} to ensure the
annotation is actually parsed.
+ */
+public class ObjectWithDefaultStringImplConverter implements Converter {
+ private final ConverterLookup lookup;
+ private final ClassLoader loader;
+ private final Class<?> defaultImpl = String.class;
+
+ public ObjectWithDefaultStringImplConverter(ConverterLookup lookup,
ClassLoader loader) {
+ this.lookup = lookup;
+ this.loader = loader;
+ }
+
+ @Override
+ public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
+ return true;
--- End diff --
Worth adding a comment here as to why this is hardcoded
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---