你知道我正在使用的jaxrs的实现方式吗?

huangapple go评论63阅读模式
英文:

How do I know what implementation of jaxrs I am using?

问题

我有一个使用Java 1.7的应用程序。它具有一些RESTful API。

我想要向一个字段添加@JsonIgnore注解,以便在API中不返回它。

例如:

Member.java

import com.fasterxml.jackson.annotation.JsonIgnore;

private java.lang.String username;
@JsonIgnore
private java.lang.String password;

但是这并没有忽略密码。

"member": {
    "password": "**************",
    "username": "richard"
}

我认为@JsonIgnore不起作用的原因是因为我使用了com.fasterxml.jackson.annotation.JsonIgnore。我应该使用来自不同库的不同注解吗?即,我的JAX-RS实现可能不是com.fasterxml.jackson吗?我该如何判断?

IntelliJ的类路径包括:

你知道我正在使用的jaxrs的实现方式吗?

(我已尝试使用net.minidev.json.annotate.JsonIgnore但没有成功)

更多信息:

pom.xml

<dependency>
    <groupId>net.minidev</groupId>
    <artifactId>json-smart</artifactId>
    <version>2.3</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.11.2</version>
</dependency>

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

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

你知道我正在使用的jaxrs的实现方式吗?

这是问题吗?有两个不同版本!我不确定2.0.5版本是从哪里来的,因为它没有在pom中定义。

你知道我正在使用的jaxrs的实现方式吗?

英文:

I have a Java 1.7 starts application. It does have some RESTful api's.

I would like to add @JsonIgnore to a filed so that it is not returned in the api.

E.g.

Member.java

import com.fasterxml.jackson.annotation.JsonIgnore;
    
private java.lang.String username;
@JsonIgnore
private java.lang.String password;

Does not ignore the password.

&quot;member&quot;: {
    &quot;password&quot;: &quot;**************&quot;,
    &quot;username&quot;: &quot;richard&quot;
}

I think the reason why @JsonIgnore does not work, is because I use com.fasterxml.jackson.annotation.JsonIgnore. Should I use a different annotation from a different library? i.e. Is my implementation of jaxrs maybe not com.fasterxml.jackson? How do I tell?

The IntelliJ classpath has:

你知道我正在使用的jaxrs的实现方式吗?

(I have tried net.minidev.json.annotate.JsonIgnore with no success)

More info:

pom.xml

&lt;dependency&gt;
    &lt;groupId&gt;net.minidev&lt;/groupId&gt;
    &lt;artifactId&gt;json-smart&lt;/artifactId&gt;
    &lt;version&gt;2.3&lt;/version&gt;
&lt;/dependency&gt;

and

&lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
    &lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
    &lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
    &lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;

你知道我正在使用的jaxrs的实现方式吗?

Is this the problem? two versions! I am not sure where the 2.0.5 version comes from, as it is not defined in the pom.

你知道我正在使用的jaxrs的实现方式吗?

答案1

得分: 1

你在这种情况下不需要使用 @JsonIgnore。你可以简单地省略你不想反序列化的变量(在这种情况下是密码),Jackson 将只返回用户名。

英文:

You don't need a @JsonIgnore in this case. You can simply omit the variable that you don't want deserialized(the password in this case) and jackson will just return you the username.

huangapple
  • 本文由 发表于 2020年8月13日 21:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63396504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定