Domanda

I am trying to use RestyGWT's JsonEncoderDecoder to encode/decode JSON objects. From their documentation I was able to do:

public interface PersonCodec extends JsonEncoderDecoder<PersonCodec>> {}

and use the encode/decode functions. However, when I do:

public interface PersonListCodec extends JsonEncoderDecoder<List<PersonCodec>> {}

it gives me compilation errors:

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)
...

Any ideas on how to make this work? Or other suggestion for encoding/decoding json to java objects?

Thanks!

È stato utile?

Soluzione

I was able to encode my list using the following piece of code:

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

Altri suggerimenti

I wrap my List in an Object since I am in control of the output.

@XmlRootElement
public class WrapperResult {
    protected List<Person> result;
}

Then I can encode and decode lists with no problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top