1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.issues.issue133;
17
18 import java.awt.Point;
19
20 import junit.framework.TestCase;
21
22 import org.yaml.snakeyaml.Yaml;
23 import org.yaml.snakeyaml.introspector.Property;
24 import org.yaml.snakeyaml.nodes.NodeTuple;
25 import org.yaml.snakeyaml.nodes.Tag;
26 import org.yaml.snakeyaml.representer.Representer;
27
28
29
30
31 public class StackOverflowTest extends TestCase {
32 public void testDumpRecursiveObject() {
33 try {
34 Yaml yaml = new Yaml();
35
36 yaml.dump(new Point());
37 fail("getLocation() is recursive.");
38 } catch (Throwable e) {
39 assertNull("StackOverflow has no message: " + e.getMessage(), e.getMessage());
40 }
41 }
42
43
44
45
46
47
48
49
50
51 private class PointRepresenter extends Representer {
52
53 @Override
54 protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
55 Object propertyValue, Tag customTag) {
56 if (javaBean instanceof Point && "location".equals(property.getName())) {
57 return null;
58 } else {
59 return super
60 .representJavaBeanProperty(javaBean, property, propertyValue, customTag);
61 }
62 }
63 }
64
65 public void testDump() {
66 Yaml yaml = new Yaml(new PointRepresenter());
67 String output = yaml.dump(new Point());
68 assertEquals("!!java.awt.Point {x: 0, y: 0}\n", output);
69 }
70 }