Java GWT Jackson APT';I don’我猜不出类名
在使用示例完成其余部分之后,我开始序列化我的实际底层对象,并发现它总是会返回一个错误,即无法猜测我试图序列化的类。这是一个高度简化的示例,说明了我正在尝试做的事情,以及对我来说有意义的注释 我想序列化一组基本体(或装箱的基本体)对象,在本例中是一个int和一个string。我的实际类也是所有基本类型(或装箱基本类型)Java GWT Jackson APT';I don’我猜不出类名,java,gwt,gwt-jackson-apt,Java,Gwt,Gwt Jackson Apt,在使用示例完成其余部分之后,我开始序列化我的实际底层对象,并发现它总是会返回一个错误,即无法猜测我试图序列化的类。这是一个高度简化的示例,说明了我正在尝试做的事情,以及对我来说有意义的注释 我想序列化一组基本体(或装箱的基本体)对象,在本例中是一个int和一个string。我的实际类也是所有基本类型(或装箱基本类型) @JSONMapper public static interface TestMapper extends ObjectMapper<TestElmt>{ T
@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;
}
}
@JSONMapper
公共静态接口TestMapper扩展了ObjectMapper{
TestMapper实例=新的Webworkers_TestMapperImpl();
}
公共静态类TestElmt{
List inerVar=new ArrayList();
公共无效补遗(测试elmt){
添加(elmt);
}
公共列表getElements(){
返回变量;
}
}
@JSONMapper
公共静态类测试{
公共静态测试映射器=新测试映射器();
int x;
弦y;
测试(整数X,字符串Y){
x=x;
y=y;
}
}
但我得到的错误是:
错误:java:创建源文件时出错
java.lang.IllegalArgumentException:无法猜测
client.myEnclosingClass.test
问题中的代码有两个问题不允许编译: 首先,测试类应命名为
test
-capital T-,而不是test
-small T-
其次,类测试中应该有一个无参数构造函数,否则反序列化程序将不知道如何创建类的新实例,它将被生成,但在其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做出了一些假设,并使用了一些约定来生成底层序列化程序/反序列化程序。问题中的代码有两个问题不允许编译: 首先,测试类应命名为
test
-capital T-,而不是test
-small T-
其次,类测试中应该有一个无参数构造函数,否则反序列化程序将不知道如何创建类的新实例,它将被生成,但在其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做出了一些假设,并使用了一些约定来生成底层的序列化程序/反序列化程序。通常,您不需要用JSONMapper标记测试类,只需注释接口或根类即可,说可能是类名的问题
test
您是否尝试了test
isstead?通常您不需要用JSONMapper标记测试类,注释接口或根类就足够了,说类名test
可能有问题,您是否尝试使用test
isstead?