我的示例代码:
private void saveData() {
ObjectMapper mapper = new ObjectMapper();
try {
mapper.writeValue( new File ( "test.json" ), Paths.get( "/home/joshua/") );
} catch ( IOException e ) {
System.out.println ( "Unable to write json" );
// TODO Auto-generated catch block
e.printStackTrace();
}
}
错误:
com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: sun.nio.fs.UnixPath["parent"]->sun.nio.fs.UnixPath["parent"]->sun.nio.fs.UnixPath["root"])
当我试图写出一条路径时,杰克逊为什么会破门?