make org.springframework.security.oauth使用com.fasterxml.jackson而不是org.codehaus.jackson

问题描述 投票:1回答:1

我有使用org.springframework.security.oauthspring-boot-starter-data-restspring-boot-starter-web的Spring项目。

一切都运作良好,但我想使用@JsonIgnore注释从域对象中排除一些字段。这不起作用。我检查了两个:com.fasterxml.jackson.annotation.JsonIgnoreorg.codehaus.jackson.annotate.JsonIgnore

我的mvn dependency:tree显示:

[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:1.5.9.RELEASE:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile

[INFO] org.springframework:na-punkty-data-rest:war:0.1.0
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.9.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile

[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.11.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile

我没有在我的代码中直接使用org.codehauscom.fasterxml中的任何类(我只尝试在一个地方使用@JsonIgnore)。在我看来,我应该摆脱双倍的实施,并让oAuth使用com.fasterxml。但我不确定这是一条好路,如何实现呢?

我试图建立https://spring.io/guides/gs/accessing-data-rest/并使用@JsonIgnore并且它在那里工作,但是mvn dependency:tree只显示了杰克逊映射器的一个实现(com.fasterxml)。

有人可以帮我吗?

spring maven jackson spring-data-rest spring-security-oauth2
1个回答
0
投票

晚上好,

我找到了@JsonIgnore无效的原因。这是一个错字:(

我从大写字母开始私人领域:

@JsonIgnore
private String Roles;

将其更改为

@JsonIgnore
private String roles;

它开始工作了。当然我必须使用适当的@JsonIgnore实现,在这种情况下它是com.fasterxml.jackson.annotation.JsonIgnore

很抱歉发布此问题。一切都很好。我是瞎子。

© www.soinside.com 2019 - 2024. All rights reserved.