Wildfly 和 Jackson @JsonIgnore 注释

2023-12-06

我对 Wildfly 和 Java EE 的某些部分相当陌生。

我有一个使用 RestEasy 在 Wildfly 上运行的休息服务。我的“用户”实体有一个“AccessToken”实体。理想情况下,我希望能够以 JSON 形式发送用户实体,而无需同时发送访问令牌。

我做了一些研究,发现我应该能够使用 @JsonIgnore 来实现这一点。但是,此注释不可用 - 可能是我的 POM 中的错误。

如果我理解正确的话,Wildfly 使用 Jackson,因此应该“提供”注释。我使用了“bom”,我认为是所有提供的部件,但我遗漏了一些东西?

这是我的 pom.xml,它源自 IntelliJ 的快速入门:

<?xml version="1.0" encoding="UTF-8"?>
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WildFly Quickstarts: example</name>
<description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>


<properties>
    <!-- Explicitly declaring the source encoding eliminates the following 
        message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
        resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

    <!-- Define the version of the JBoss BOMs we want to import to specify 
        tested stacks. -->
    <version.jboss.bom>8.0.0.Final</version.jboss.bom>

    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.surefire.plugin>2.16</version.surefire.plugin>
    <version.war.plugin>2.5</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>


<dependencyManagement>
    <dependencies>
        <!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
            of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) 
            of artifacts. We use this here so that we always get the correct versions 
            of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
            read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
            for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
            stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
            from the Hibernate family of projects) -->
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-with-tools</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- First declare the APIs we depend on and need for compilation. All 
        of them are provided by JBoss WildFly -->

    <!-- Import the CDI API, we use provided scope as the API is included in 
        JBoss WildFly -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
        as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included 
        in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JPA API, we use provided scope as the API is included in 
        JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the EJB API, we use provided scope as the API is included in 
        JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.5</version>
    </dependency>


    <!-- JSR-303 (Bean Validation) Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Import the JSF API, we use provided scope as the API is included in 
        JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Now we declare any tools needed -->

    <!-- Annotation processor to generate the JPA 2.0 metamodel classes for 
        typesafe criteria queries -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Annotation processor that raising compilation errors whenever constraint 
        annotations are incorrectly used. -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Needed for running tests (you may also use TestNG) -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Optional, but highly recommended -->
    <!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) 
        JPA from JUnit/TestNG -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Facebook library -->
    <dependency>
        <groupId>com.restfb</groupId>
        <artifactId>restfb</artifactId>
        <version>1.17.0</version>
    </dependency>


</dependencies>

<build>
    <!-- Maven will append the version to the finalName (which is the name 
        given to the generated war, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <!-- The WildFly plugin deploys your war to a local WildFly container -->
        <!-- To use, run: mvn package wildfly:deploy -->

    </plugins>
</build>

<profiles>
    <profile>
        <!-- The default profile skips all tests, though you can tune it to run 
            just unit tests based on a custom pattern -->
        <!-- Seperate profiles are provided for running all tests, including Arquillian 
            tests that execute in the specified container -->
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.surefire.plugin}</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>

我确实尝试添加:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.6.4</version>
    </dependency>

这让我可以使用 @JsonIgnore,但它仍然在返回给客户端的 JSON 中显示该字段。我想也许我的 Wildfly 使用的是旧版本的 jackson (1.x) 而不是 2? (这给我的印象是:JsonIgnoreProperties 不起作用)


注释 @JsonIgnore 是 Jackson 注释 jar 的一部分。 要包含它,请在 pom 文件中使用以下依赖项。

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.6.4</version>
</dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Wildfly 和 Jackson @JsonIgnore 注释 的相关文章

随机推荐

  • 在 Asp.net 中创建 pdf 文件

    字符串s 姓名 恩恩恩 年龄 DD 我需要将此字符串转换为 pdf 文件 有人可以帮我吗 iTextSharp 表格简介 NET 框架不包含任何处理 PDF 文件的本机方法 因此 如果您想要生成或使用 PDF 文件作为 ASP NET We
  • Javascript:如何获取 p 标签内的文本字符串数组

    假设我有一个带有很多 p 标签的字符串 var myString p Some text p p Some more Some more text p p And even some more text p 如何获取一个数组 数组中的每个项
  • Git中添加但未提交的已删除文件可以恢复吗? [复制]

    这个问题在这里已经有答案了 我是 git 的新手 我刚刚犯了一个愚蠢的错误 我通过 rm 命令删除了一些重要的文件 但是 我确实使用 git add 来添加这些文件 但没有提交 删除尚未添加 那么有什么办法可以恢复这些被删除的文件呢 任何建
  • 检查 RichTextBox 上选定的文本是否全部粗体

    如何检查 RichTextBox 上选定的文本是否全部粗体 例如 asdasdasdasd 这并不都是粗体 我都很大胆 这都是粗体 这是我编写的代码 它可以检查是否全部粗体 但速度很慢 因为它使用一一检查字符Selection Start
  • 初始化 SSL 和 libcurl 并出现“内存不足”

    我打算使用 C 程序使用 libcurl 和 openssl 执行 https 请求 我初始化了 libcurlcurl global init CURL GLOBAL ALL 如文档中所述 然后我用一个curl easy处理我初始化的内容
  • 将 std::cout 重定向到 QTextEdit

    是否可以 更重要的是如何 将输出流重定向到 QTextBox 所以如果我写std cout lt lt test 应用程序中的任何位置它都会被重定向到我定义的文本框吗 我尝试了显而易见的方法 其中 ui textEdit 是指向文本编辑框的
  • 如何限制对 PHP 文件的访问?

    我想限制对我的服务器上的 PHP 文件的访问 该 PHP 文件从 HTTP GET 请求获取数据并将其附加到文件中 简单的 但我不希望执行此 PHP 文件 除非 HTTP 请求是从我开发的智能手机应用程序中生成的 我不想单独验证每个用户的身
  • 如何禁用客户端 GRPC 服务器证书主机名验证?

    目前我正在为 gRPC 客户端设置通道身份验证 如下所示 std shared ptr
  • 在matlab中设置对象数组的对象属性值

    我创建了一个对象数组 我想在向量运算中分配一个属性值 而不使用 for 循环 不幸的是我得到一个错误 问题的简化示例 classdef clsMyClass lt handle properties dblMyProperty1 end m
  • 将四位数年份值转换为 Date 类

    我的数据集中有一个整数列 其中有四位数字的年份值 例如 c 2001 2002 2002 2002 2003 2005 我尝试将四位数年份转换为班级Date using as Date year lt as Date as characte
  • PHP 中是否有 shell_exec 和 proc_open 的替代方案?

    我好像不能用shell exec or proc open在我的共享服务器上 当我尝试使用它时收到的消息是 警告 出于安全原因 第 4 行 home georgee public html admin email php 中的 shell
  • Tkinter 文档与 PEP 8 相矛盾

    PEP 8 states 应避免通配符导入 来自 import 因为它们使命名空间中存在哪些名称变得不清楚 从而使读者和许多自动化工具感到困惑 尽管如此官方文档是矛盾的 要使用 Tkinter 您只需要一个简单的导入语句 import tk
  • 整个应用程序的通用页脚 [Android]

    好吧 我想知道这是否可以做到 我所需要的只是一个常见的页脚 如栏 其中将包含将要显示的广告 我想知道是否有任何方法可以使我的应用程序的这一部分成为通用的 我知道包含标签 但所做的只是在引用它的任何地方添加特定的布局 这样做的作用是 每次我从
  • 来自 x509 中字符缓冲区的 EVP_PKEY (PKCS7)

    我有一个 DER 证书 我正在从中检索 unsigned char 缓冲区中的公钥 如下所示 这是正确的获取方式吗 pStoredPublicKey X509 get pubkey x509 if pStoredPublicKey NULL
  • 32 位浮点数相加。

    关于浮点数 我学到的东西比我想知道的还要多 可以说我需要添加 1 10000000 00000000000000000000000 1 01111000 11111000000000000000000 2的补码形式 第一位是符号 接下来的
  • 以问号开头的 HTML 标签?

    我正在学习谷歌应用程序脚本 并且在this教程中 我看到了一些奇怪的语法 and h1 Messages h1 ul ul
  • HERE Map/MapView 不使用 MapFragment

    有没有办法获得Map or MapView没有放置一个MapFragmet里面一个Layout
  • .NET 垃圾收集在这里无法正常工作?

    我们有一个在 NET 4 0 IIS 7 ASP NET 4 GB 服务器 RAM 上运行的图像转换脚本 用于调整大图像的大小 因此需要大量内存 第一个脚本将内存使用率增加到几乎 100 几乎没有为正在运行的 SQL Server 留下任何
  • 更改 R 中图形的字体

    在我的研究中 我使用 R 生成各种图表 我发现大多数图表都带有各种大小的 Sans Serif 字体 如何将图表中的所有文本 x 标签 y 标签 标题 图例等 更改为统一字体 例如Times New Roman 12pt 粗体 您可以使用外
  • Wildfly 和 Jackson @JsonIgnore 注释

    我对 Wildfly 和 Java EE 的某些部分相当陌生 我有一个使用 RestEasy 在 Wildfly 上运行的休息服务 我的 用户 实体有一个 AccessToken 实体 理想情况下 我希望能够以 JSON 形式发送用户实体