我试图用snakeYAML 1.13序列化一个包含hashmap的类,并且得到了一个非常奇怪的stackoverflow:
完整的代码在类中还有一些其他内容,为了简单起见我将其删除
使用的示例代码:
import java.awt.Point;
import java.util.HashMap;
import org.yaml.snakeyaml.Yaml;
class TestClass
{
public static void main(final String args2[])
{
IZSkinFile f = new IZSkinFile();
HashMap<String,Point> ep = f.getElementPositions();
ep.put("another unimportant name",new java.awt.Point(10, 10));
System.out.println(new Yaml().dump(f));
}
}
class IZSkinFile
{
public IZSkinFile(String uprogram)
{
elementPositions = new HashMap<>();
}
public IZSkinFile(){
elementPositions = new HashMap<>();
}//serialisierer....
// private HashMap<String,String> elementDefinitions;//name>typ (Grafik/text/Schriftart)
private HashMap<String,Point> elementPositions; //basisposition des elements
public HashMap<String, Point> getElementPositions()
{
return elementPositions;
}
public void setElementPositions(HashMap<String, Point> elementPositions)
{
this.elementPositions = elementPositions;
}
}
,结果在Stackoverflow之后(仅显示上端和下端以保存不必要的行:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:122)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at org.yaml.snakeyaml.nodes.Tag.<init>(Tag.java:87)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:74)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
...
...
...
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:106)
答案 0 :(得分:1)
发现了愚蠢的问题......
某种程度上java.awt.Point
混乱,即使它只有2个属性。现在使用带有2个整数的int[]
数组进行存储,因为这个错误让我发疯了。