杰克逊jboss eap6.1.1注释不起作用 [英] jackson jboss eap6.1.1 annotations not working
问题描述
我一直在尝试使杰克逊注释在EAP 6.1.1服务器上的JBoss RestEasy应用程序中工作.更确切地说,我想让 JacksonPolymorphicDeserialization 像在
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;
}
}
现在,我还进行了一些配置,并确保通过战争部署将Jacksson模块加载到Jboss中.并确保在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"} ]
}
我期望得到一个@type
名称,其中包含implementedrequest
字段.这是我的第一次尝试;最终,我也希望抽象数组像这样工作.但是我什至无法正常工作.
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的默认值为1.c分支,在org.codehaus
下可用.两种方法都在核心下起作用.后来将其移至其他分支和工件.
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.
这篇关于杰克逊jboss eap6.1.1注释不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!