我正在尝试在Wildfly 8上设置REST服务,该服务返回带有自定义枚举值的JSON.我知道Wildfy使用Jackson 2.3进行序列化.我也知道,当使用Jackson ObjectMapper注册JaxbAnnotationModule时,序列化程序会产生正确的结果.问题是,如何配置我的Wildfly实例或我的web项目以使用此模块.
好的,为了使这个更清楚,一个简单的例子.
首先,这可以正常工作并生成我需要的结果.
@XmlEnum
public enum TestEnum
@XmlEnumValue("2")
TWO;
}
public class Test {
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule();
mapper.registerModule(jaxbModule);
try {
mapper.writeValue(System.out, TestEnum.TWO);
} catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud)
这会产生正确的输出:"2"
现在,我的问题服务
@Path("test")
@RequestScoped
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class TestRestService {
@GET
@Path("/json")
@Produces({MediaType.APPLICATION_JSON})
public TestEnum testJson() {
return TestEnum.TWO;
}
}
Run Code Online (Sandbox Code Playgroud)
这返回"TWO",这不是我想要的.
我没有在"jboss-deployment-structure.xml"和"web.xml"中配置任何内容.
我没有使用maven所以任何pom.xml解决方案对我来说都不会对我有用,除非指向我.
我在这里阅读了文档,但找不到启用JaxbAnnotationModule的选项.
任何定制适用于JSON和XML的枚举值的可能性都是不可能的.
-----更新-----
理论上,该解决方案已在此处发布
如果我使用该解决方案尝试使用Jackson …
我有一个在Tomcat 8.5上运行的Spring-Boot(1.5.3)应用程序。在其中,我有一个带有单个参数的RestController。
此参数会自动解码-对我的应用程序中的所有其他控制器都很好,但是对此,我需要原始请求数据,因为它们将在另一个请求中使用。请注意,我希望仅对此控制器/请求禁用自动解码,并在其他地方保持正常行为。
@RestController
@RequestMapping("/rest/test")
public class TestController {
@RequestMapping("/test")
public ResponseEntity<String> test(@RequestParam final String test){
return ResponseEntity.ok("Requested: " + test);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我发送访问
curl localhost/rest/test/test?test=%C3%B6%20%C3%A4
Run Code Online (Sandbox Code Playgroud)
我收到输出:
Requested: ö ä
Run Code Online (Sandbox Code Playgroud)
我想拥有
Requested: %C3%B6%20%C3%A4
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?