GWT-Jackson-APT 无法猜测类名
GWT-Jackson-APT Couldn't make a guess for classname
在使用示例完成其余所有工作后,我绑定到序列化我的实际底层对象,发现它总是会返回一个关于无法猜测 class I'我正在尝试连载。这是我正在尝试做的事情的高度简化示例,以及对我来说似乎对如何做有意义的注释。
我想序列化原始(或盒装原始)对象的 List<>,在本例中为一个 int 和一个字符串。我的实际 class 也是所有原始(或盒装原始)类型。
@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;
}
}
但我得到的错误是:
Error:java: error while creating source file
java.lang.IllegalArgumentException: couldn't make a guess for
client.myEnclosingClass.test
问题中的代码有两个问题导致无法编译:
首先,测试 class 应命名为 Test
- 大写 T - 而不是 test
- 小写 t -。
其次,在 class 测试中应该有一个无参数构造函数,否则反序列化器将不知道如何创建 class 的新实例,它会生成但会出现编译错误在其 create
方法中。
如果我们像这样更改测试 class 一切都应该有效
@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做了一些假设并使用了一些约定来生成底层serializers/deserializers。
在使用示例完成其余所有工作后,我绑定到序列化我的实际底层对象,发现它总是会返回一个关于无法猜测 class I'我正在尝试连载。这是我正在尝试做的事情的高度简化示例,以及对我来说似乎对如何做有意义的注释。
我想序列化原始(或盒装原始)对象的 List<>,在本例中为一个 int 和一个字符串。我的实际 class 也是所有原始(或盒装原始)类型。
@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;
}
}
但我得到的错误是:
Error:java: error while creating source file java.lang.IllegalArgumentException: couldn't make a guess for client.myEnclosingClass.test
问题中的代码有两个问题导致无法编译:
首先,测试 class 应命名为 Test
- 大写 T - 而不是 test
- 小写 t -。
其次,在 class 测试中应该有一个无参数构造函数,否则反序列化器将不知道如何创建 class 的新实例,它会生成但会出现编译错误在其 create
方法中。
如果我们像这样更改测试 class 一切都应该有效
@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做了一些假设并使用了一些约定来生成底层serializers/deserializers。