我正在尝试将java.util.GregorianCalendar
类添加到Apache tinkerpop 3.3.3上的kryo序列化程序中。为了防止发生以下异常
Exception in thread "main" java.lang.IllegalArgumentException: Class is not registered: java.util.GregorianCalendar
Note: To register this class use: kryo.register(java.util.GregorianCalendar.class);
at org.apache.tinkerpop.shaded.kryo.Kryo.getRegistration(Kryo.java:484)
at org.apache.tinkerpop.gremlin.structure.io.gryo.AbstractGryoClassResolver.writeClass(AbstractGryoClassResolver.java:110)
at org.apache.tinkerpop.shaded.kryo.Kryo.writeClass(Kryo.java:514)
at org.apache.tinkerpop.shaded.kryo.Kryo.writeClassAndObject(Kryo.java:619)
at org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.shaded.ShadedKryoAdapter.writeClassAndObject(ShadedKryoAdapter.java:49)
at org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.shaded.ShadedKryoAdapter.writeClassAndObject(ShadedKryoAdapter.java:24)
因为tinkerpop使用某种"阴影" kryo版本我只是不能打电话给kryo.register()
。到目前为止我试过了
GryoMapper mapper =
GryoMapper.build().addCustom(java.util.GregorianCalendar.class).create();
List l = mapper.getRegisteredClasses();
并且能够观察到java.util.GregorianCalendar
已注册。但是我不知道接下来我应该做什么来使用这个自定义映射器我检查了javadocs并且感到困惑。我还使用下面的代码将TinkerGraph
实例写入文件。
任何帮助将不胜感激。
this.graph.io(IoCore.gryo()).writeGraph(filePath);
答案 0 :(得分:2)
我认为如果您有GryoMapper
个实例,那么我就像这样直接实例化GryoWriter
:
File file = new File("C:/myfile.txt");
OutputStream fos = new FileOutputStream(file);
GryoMapper mapper = GryoMapper.build().addCustom(java.util.GregorianCalendar.class).create()
GryoWriter writer = GryoWriter.build().mapper(mapper).create()
writer.writeGraph(fos, graph)