GWT-Jackson-APT无法猜出classname

问题描述 投票:0回答:1

在完成剩下的全部工作后,我绑定了序列化我的实际底层对象,并发现它总是会回复一个关于无法猜测我正在尝试序列化的类的错误。这是我正在尝试做的高度简化的示例,以及对我来说似乎有意义的注释。

我想序列化一个List <>的原始(或盒装原始)对象,在这种情况下是一个int和一个字符串。我的实际类也是原始(或盒装原始)类型。

@JSONMapper
public static interface TestMapper extends ObjectMapper<TestElmt>{
    TestMapper INSTANCE = new Webworkers_TestMapperImpl();
}

public static class TestElmt {

    List<test> inerVar = new ArrayList<>();

    public void addElement(test elmt){
        inerVar.add(elmt);
    }
    public List<test> getElements(){
        return inerVar;
    }

}

@JSONMapper
public static class test{

    public static test_MapperImpl MAPPER = new test_MapperImpl();

    int x;
    String y;

    test(int X,String Y){
        x = X;
        y = Y;
    }
}

但我得到的错误是:

错误:java:创建源文件时出错java.lang.IllegalArgumentException:无法猜测client.myEnclosingClass.test

java gwt gwt-jackson-apt
1个回答
2
投票

问题中的代码有两个问题,不允许它编译:

首先,测试类应命名为Test - 大写字母T - 而不是test - 小t - 。

其次,类测试中应该没有args构造函数,否则反序列化器不会知道如何创建类的新实例,它将被生成但在其create方法中会有编译错误。

如果我们改变这样的测试类,一切都应该有效

@JSONMapper
public static class Test {

    public static Test_MapperImpl MAPPER = new Test_MapperImpl();

    int x;
    String y;

    public Test() {
    }

    Test(int X, String Y){
            x = X;
            y = Y;
    }
}

这是因为gwt-jackson-apt做了一些假设并使用一些约定来生成底层序列化器/反序列化器。

© www.soinside.com 2019 - 2024. All rights reserved.