jackson jboss eap6.1.1 注释不起作用 [英] jackson jboss eap6.1.1 annotations not working
问题描述
我一直在尝试在 EAP 6.1.1 服务器上的 JBoss RestEasy 应用程序中使用 Jackson 注释.更确切地说,我想让 JacksonPolymorphicDeserialization 像 done 这里.
I have been trying to get Jackson annotations working in the JBoss RestEasy application on a EAP 6.1.1 server. To be more exact I want to get the JacksonPolymorphicDeserialization working through there annotation like done here.
现在看起来很简单,但由于某种原因,它并没有真正起作用.我得到以下代码:
Now it seems simple enough but for some reason it’s not really working. I got the following code:
package example.model;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type",visible = true)
@JsonSubTypes({@JsonSubTypes.Type(value = ImplementedRequest.class, name = "implementedrequest")})
public abstract class Request {
}
以及抽象类的实现:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true)
public class ImplementedRequestextends Request {
@NotEmpty
private Person applicant;
private List<AbstractApplicationPart> applications;
}
我创建了一个发出请求并处理请求的端点:
I created a endpoint that makes a request and processes a request:
@Path("serviceRequest")
@Named("RequestResource")
@RequestScoped
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ValidateRequest
@IgnoreMediaTypes(MediaType.APPLICATION_JSON)
public class RequestResource {
public Boolean saveRequest( @Valid Request request, @Context HttpServletRequest req) throws JAXBException, AnError {
//Some awesome processing happens here
}
public Response getDummyData() {
// Creates and fills the ImplementedRequestextends
return result;
}
}
现在我也做了一些配置,并确保我在 Jboss 中加载了带有 war 部署的 Jackson 模块.并确保在我的 pom 中我的版本与模块相同.
Now I also did some configuration and made sure I load the Jackson modules in Jboss with the war deployment. And made sure in my pom I have the same version as the Modules.
我现在的期望是,如果我打电话,我会得到类似的信息:
My expectation is now that if I do a call I get something like:
{
"applicant": { "name":"Dummy data", "age":31},
"applications": [ {"sport":"soccer"},{"sport":"judo"} ]
}
我希望得到一个带有 implementedrequest
字段的 @type
名称.这是我的第一次尝试;最终我也想让抽象数组像这样工作.但我什至无法让它工作.
I was expecting to get a @type
name with the field implementedrequest
. This is my first attempt; eventually I also want to have the abstract array work like this. But I can't even get this working.
推荐答案
所以最后我弄清楚出了什么问题.
So in the end I figured out what went wrong.
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
是不是有问题.Jackson 有 2 个版本并且都可以工作,但 JBoss EAP6.1.1 的默认版本是 org.codehaus
下的 1.X 分支.问题这两种方法都在核心下工作.它后来移到了不同的分支和工件.
Is the problem. Jackson has 2 versions and both work, but the default for JBoss EAP6.1.1 is the 1.X branch wich is available under org.codehaus
. The problem both methods work under the core. It's later moved to a different branch and artifact.
这篇关于jackson jboss eap6.1.1 注释不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!