gpt4 book ai didi

java - Tinkerpop 注册自定义类 kryo

转载 作者:行者123 更新时间:2023-11-30 02:09:10 25 4
gpt4 key购买 nike

我正在尝试将 java.util.GregorianCalendar 类添加到 Apachetinkerpop 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);

最佳答案

我认为如果您有一个 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)

关于java - Tinkerpop 注册自定义类 kryo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50574258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com