Add one more example with JodaTime (as a JavaBean property)
diff --git a/src/test/java/examples/jodatime/JodaTimeContructor.java b/src/test/java/examples/jodatime/JodaTimeContructor.java
index fb828e5..d7e301d 100644
--- a/src/test/java/examples/jodatime/JodaTimeContructor.java
+++ b/src/test/java/examples/jodatime/JodaTimeContructor.java
@@ -20,11 +20,11 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
-import org.yaml.snakeyaml.constructor.SafeConstructor;
+import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.Tag;
-public class JodaTimeContructor extends SafeConstructor {
+public class JodaTimeContructor extends Constructor {
public JodaTimeContructor() {
this.yamlConstructors.put(Tag.TIMESTAMP, new ConstructJodaTimestamp());
}
diff --git a/src/test/java/examples/jodatime/JodaTimeExampleTest.java b/src/test/java/examples/jodatime/JodaTimeExampleTest.java
index c413a47..0f87d80 100644
--- a/src/test/java/examples/jodatime/JodaTimeExampleTest.java
+++ b/src/test/java/examples/jodatime/JodaTimeExampleTest.java
@@ -40,4 +40,17 @@
DateTime time = (DateTime) yaml.load("2001-09-09T01:46:40Z");
assertEquals(new DateTime(timestamp, DateTimeZone.UTC), time);
}
+
+ public void testLoadBean() throws IOException {
+ MyBean bean = new MyBean();
+ bean.setId("id123");
+ DateTime etalon = new DateTime(timestamp, DateTimeZone.UTC);
+ bean.setDate(etalon);
+ Yaml dumper = new Yaml(new JodaTimeRepresenter());
+ String doc = dumper.dump(bean);
+ // System.out.println(doc);
+ Yaml loader = new Yaml(new JodaTimeContructor());
+ MyBean parsed = (MyBean) loader.load(doc);
+ assertEquals(etalon, parsed.getDate());
+ }
}
diff --git a/src/test/java/examples/jodatime/MyBean.java b/src/test/java/examples/jodatime/MyBean.java
new file mode 100644
index 0000000..8307e5e
--- /dev/null
+++ b/src/test/java/examples/jodatime/MyBean.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2008-2010, http://code.google.com/p/snakeyaml/
+ *
+ * Licensed 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 examples.jodatime;
+
+import org.joda.time.DateTime;
+
+public class MyBean {
+ private String id;
+ private DateTime date;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public DateTime getDate() {
+ return date;
+ }
+
+ public void setDate(DateTime date) {
+ this.date = date;
+ }
+}
\ No newline at end of file