gpt4 book ai didi

json - RestyGWT - JsonEncoderDecoder 是否适用于列表?

转载 作者:行者123 更新时间:2023-12-04 05:21:21 25 4
gpt4 key购买 nike

我正在尝试使用 RestyGWT 的 JsonEncoderDecoder 来编码/解码 JSON 对象。从他们的文档中,我能够做到:

public interface PersonCodec extends JsonEncoderDecoder<PersonCodec>> {}

并使用编码/解码功能。但是,当我这样做时:
public interface PersonListCodec extends JsonEncoderDecoder<List<PersonCodec>> {}

它给了我编译错误:
java.lang.NullPointerException
at org.fusesource.restygwt.rebind.BaseSourceCreator.<init>(BaseSourceCreator.java:76)
at org.fusesource.restygwt.rebind.JsonEncoderDecoderClassCreator.<init>(JsonEncoderDecoderClassCreator.java:79)
at org.fusesource.restygwt.rebind.ExtendedJsonEncoderDecoderClassCreator.createComposerFactory(ExtendedJsonEncoderDecoderClassCreator.java:46)
at org.fusesource.restygwt.rebind.BaseSourceCreator.create(BaseSourceCreator.java:210)
at org.fusesource.restygwt.rebind.JsonEncoderDecoderGenerator.generate(JsonEncoderDecoderGenerator.java:38)
at com.google.gwt.core.ext.IncrementalGenerator.generateNonIncrementally(IncrementalGenerator.java:40)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:657)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:79)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:276)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:265)
at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleGwtCreate(UnifyAst.java:355)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleMagicMethodCall(UnifyAst.java:433)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.endVisit(UnifyAst.java:237)
at com.google.gwt.dev.jjs.ast.JMethodCall.traverse(JMethodCall.java:243)
at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
...

关于如何使这项工作的任何想法?或将 json 编码/解码为 java 对象的其他建议?

谢谢!

最佳答案

我能够使用以下代码对我的列表进行编码:

JSONArray batch = new JSONArray();
int idx=0;
for (Pojo i : buffer) {
batch.set(idx++, CODEC.encode(i));
}

关于json - RestyGWT - JsonEncoderDecoder 是否适用于列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13655916/

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