如何将 jgrapht 简单图序列化为 json?
我有一个来自jgrapht的简单有向图,我正在尝试使用jackson将其序列化为JSON文件,如下所示:
ObjectMapper mapper = new ObjectMapper();
File output = new File("P:\\tree.json");
ObjectWriter objectWriter = mapper.writer().withDefaultPrettyPrinter();
objectWriter.writeValue(output,simpleDirectedGraph);
但是我得到这个错误:
线程“main” com.fasterxml.jackson.databind.JsonMappingException 中的异常:没有为类 org.jgrapht.graph.AbstractBaseGraph$ArrayListFactory 找到序列化程序,也没有发现任何属性来创建 BeanSerializer (以避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (通过引用链: org.jgrapht.graph.SimpleDirectedGraph[“edgeSetFactory”]) at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69) atcom.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) atcom.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130) at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1387) at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1088) at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:909) at ms.fragment.JSONTreeGenerator.main(JSONTreeGenerator.java:45) atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.delegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
我已经看到有一个GmlExporter,但我对json感兴趣...我该怎么做?