Java JsonGenerationException:无法写入字段名
我的问题在于jacksonfasterxml库中实现的json序列化领域。我有一系列端点,通过这些端点,我可以在后端和MVVM前端框架之间交换内容。这是可行的,但现在我有点卡住了,因为我要处理用户创建/注册 这是表示我的应用程序中的组的模型(实体)(我省略了不相关的导入声明和JPA注释): ……惨败:Java JsonGenerationException:无法写入字段名,java,json,jax-rs,jackson2,Java,Json,Jax Rs,Jackson2,我的问题在于jacksonfasterxml库中实现的json序列化领域。我有一系列端点,通过这些端点,我可以在后端和MVVM前端框架之间交换内容。这是可行的,但现在我有点卡住了,因为我要处理用户创建/注册 这是表示我的应用程序中的组的模型(实体)(我省略了不相关的导入声明和JPA注释): ……惨败: << ERROR! javax.ws.rs.InternalServerErrorException: Server error serializing the requested
<< ERROR!
javax.ws.rs.InternalServerErrorException: Server error serializing the requested group "admin"
at com.vgorcinschi.rimmanew.rest.services.GroupsResourceService.getGroup(GroupsResourceService.java:54)
at com.vgorcinschi.rimmanew.services.GroupsResourceServiceTest.successfullResponse(GroupsResourceServiceTest.java:48)
在访问和分析了13个类似的投诉链接(其中3个来自stackoverflow)后,我提出了一个解决方案,这更像是一个解决办法——如果您回顾一下实体,我已经评论了@JsonValue
。如果我取消注释并注释@JsonGetter(“group_Name”)
,那么测试将通过以下输出:
{"userGroup":"admin"}
这只是一个解决办法,我决定再次求助,希望有人能够提供帮助。我可以知道您当前使用的Jackson版本吗?Jackson{-annotations,-core,-databind,-jaxrs base,-jaxrs json provider,-module jaxb annotations}所有在2.5.4我可以知道您当前使用的Jackson版本吗?Jackson{-annotations,-core,-databind,-jaxrs base,-jaxrs json provider,-module jaxb annotations}所有在2.5.4
@Test
public void successfullResponse(){
Response success = groupsResourceService.getGroup("admin");
assertTrue(success.getStatus()==200);
}
<< ERROR!
javax.ws.rs.InternalServerErrorException: Server error serializing the requested group "admin"
at com.vgorcinschi.rimmanew.rest.services.GroupsResourceService.getGroup(GroupsResourceService.java:54)
at com.vgorcinschi.rimmanew.services.GroupsResourceServiceTest.successfullResponse(GroupsResourceServiceTest.java:48)
15:05:05.857 [main] ERROR com.vgorcinschi.rimmanew.rest.services.GroupsResourceService - Serialization error: Can not write a field name, expecting a value
com.fasterxml.jackson.core.JsonGenerationException
{"userGroup":"admin"}