Clarified JavaDoc regarding how type-safe TypeDescription is and modified spring context XML accordingly. Also removed some redundant initialization values (null and false are default values).
diff --git a/src/main/java/org/yaml/snakeyaml/TypeDescription.java b/src/main/java/org/yaml/snakeyaml/TypeDescription.java
index 8df4ea0..33c3e04 100644
--- a/src/main/java/org/yaml/snakeyaml/TypeDescription.java
+++ b/src/main/java/org/yaml/snakeyaml/TypeDescription.java
@@ -34,6 +34,13 @@
/**
* Provides additional runtime information necessary to create a custom Java
* instance.
+ *
+ * In general this class is thread-safe and can be used as a singleton, the only
+ * exception being the PropertyUtils field. A singleton PropertyUtils should be
+ * constructed and shared between all YAML Constructors used if a singleton
+ * TypeDescription is used, since Constructor sets its propertyUtils to the
+ * TypeDescription that is passed to it, hence you may end up in a situation
+ * when propertyUtils in TypeDescription is from different Constructor.
*/
public class TypeDescription {
@@ -44,9 +51,9 @@
private Tag tag;
- transient private Set<Property> dumpProperties = null;
+ transient private Set<Property> dumpProperties;
transient private PropertyUtils propertyUtils;
- transient private boolean delegatesChecked = false;
+ transient private boolean delegatesChecked;
private Map<String, PropertySubstitute> properties = Collections.emptyMap();
@@ -360,6 +367,14 @@
return false;
}
+ /**
+ * This method should be overriden for TypeDescription implementations that are supposed to implement instantiation logic that is different from default one as
+ * implemented in YAML constructors.
+ * Note that even if you override this method, default filling of fields with variables from parsed YAML will still occur later.
+
+ * @param node
+ * @return
+ */
public Object newInstance(Node node) {
if (impl != null) {
try {
diff --git a/src/test/resources/examples/spring.xml b/src/test/resources/examples/spring.xml
index 415bf8c..3cb8165 100644
--- a/src/test/resources/examples/spring.xml
+++ b/src/test/resources/examples/spring.xml
@@ -39,8 +39,11 @@
<property name="dataRegistry" ref="dataRegistry" />
</bean>
+ <bean id="propertyUtils" class="org.yaml.snakeyaml.introspector.PropertyUtils" scope="singleton" />
+
<bean id="beanConstructorWithCustomTypeDescriptions" class="org.yaml.snakeyaml.constructor.Constructor" scope="prototype">
<constructor-arg ref="testEntityDescription" />
+ <property name="propertyUtils" ref="propertyUtils" />
</bean>
<bean id="javabeanYamlWithCustomTypeDescriptions" class="org.yaml.snakeyaml.Yaml" scope="prototype">