简体   繁体   English

无法识别的字段类未标记为可忽略

[英]Unrecognized field class not marked as ignorable

Having the following:具备以下条件:

web.xml:网页.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <display-name>avdisws</display-name>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>paqA.paqB.paqC.RestApplication</param-value>
        </init-param>       
    </servlet>

</web-app>

Class Book.java:类 Book.java:

@XmlRootElement(name = "book")
@XmlType(propOrder = {"title", "author", "price"})
public class Book {

    private String title; 
    private String author; 
    private Double price;

    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }

    public Double getPrice() {
        return price;
    }
    public void setPrice(Double price) {
        this.price = price;
    }

}

Class BookService.java:类 BookService.java:

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

@Path("bookService")
@Produces(MediaType.APPLICATION_JSON + "; charset=ISO-8859-15")
@Consumes(MediaType.APPLICATION_JSON)
public class BookService {

    @POST
    @Path("test")
    public Book getBook(@Context HttpServletRequest request, Book book) {

        Book returnedBook = new Book();
            returnedBook.setAuthor("Test Author");
            returnedBook.setTitle("Test Title");
            returnedBook.setPrice(99.99);

        return returnedBook;
    }

}

Class RestApplication:类 RestApplication:

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class RestApplication extends Application {

    private Set<Object> singletons = new HashSet<Object>();

    public RestApplication() {
        super();
        singletons.add(new BookService());
    }

    @Override
    public Set<Object> getSingletons() {
        return singletons;
    }

}

In my local JBoss AS 6 environment, I'am able to call http://localhost:8080/avdisws/bookService/test properly with this JSON:在我本地的JBoss AS 6环境中,我可以使用这个 JSON 正确调用http://localhost:8080/avdisws/bookService/test

{
    "book":
    {
        "title": "Some book",
        "author": "Some author",
        "price": 89.21
    }
}

BUT in the DESA environment, with Jboss EAP 7.1 I get:但是在 DESA 环境中,使用Jboss EAP 7.1我得到:

Unrecognized field "book" (class paqA.paqB.paqC.Book), not marked as ignorable无法识别的字段“book”(类 paqA.paqB.paqC.Book),未标记为可忽略

If I do the call with next JSON it doesnt fails:如果我使用下一个 JSON 进行调用,它不会失败:

{
        "title": "Some book",
        "author": "Some author",
        "price": 89.21
    }

These are the libraries I am using:这些是我正在使用的库:

javax.servlet-api-3.1.0.jar
jaxrs-api-3.0.10.Final.jar
resteasy-jaxrs-3.0.10.Final.jar
resteasy-client-3.0.10.Final.jar
resteasy-jaxb-provider-3.0.10.Final.jar
resteasy-jettison-provider-3.0.10.Final.jar
httpclient-4.5.3.jar
httpcore-4.4.6.jar
commons-io-2.6.jar
commons-logging-1.2.jar
jettison-1.3.8.jar

Using @JsonIgnoreProperties(ignoreUnknown = true) does not solve the problem.使用@JsonIgnoreProperties(ignoreUnknown = true)不能解决问题。

Thanks!谢谢!

For me, this solve the problem:对我来说,这解决了问题:

<?xml version="1.0" encoding="UTF-8"?>  
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未被识别的字段,未标记为可忽略 - unrecognized field, not marked as ignorable 无法保存用户:无法识别的字段类未标记为可忽略 - Unable to save users: Unrecognized field class not marked as ignorable JSON 到 Java 对象 - 无法识别的字段,未标记为可忽略 - JSON to Java object - Unrecognized field, not marked as ignorable Spring Jackson-无法识别的字段“ response”在以下位置未标记为可忽略 - Spring Jackson - Unrecognized field \“response\” not marked as ignorable at Jackson Json 反序列化:无法识别的字段“...”,未标记为可忽略 - Jackson Json Deserialisation: Unrecognized field “…” , not marked as ignorable Jackson 与 JSON:无法识别的字段,未标记为可忽略 - Jackson with JSON: Unrecognized field, not marked as ignorable jackson java无法识别的字段未标记为可忽略 - jackson java Unrecognized field not marked as ignorable JSON:无法识别的字段“值”( <objectClass> ),没有标记为可忽略的 - JSON : Unrecognized field “value” (<objectClass>), not marked as ignorable Wiremock 存根错误:“无法识别的字段 \"timestamp\"(类 com.github.tomakehurst.wiremock.common.Errors),未标记为可忽略” - Wiremock stubbing error: "Unrecognized field \"timestamp\" (class com.github.tomakehurst.wiremock.common.Errors), not marked as ignorable" UnrecognizedPropertyException:无法识别的字段“开始”(类org.jboss.resteasy.spi.ResteasyProviderFactory),未标记为可忽略 - UnrecognizedPropertyException: Unrecognized field “start” (Class org.jboss.resteasy.spi.ResteasyProviderFactory), not marked as ignorable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM