我有使用org.springframework.security.oauth
,spring-boot-starter-data-rest
和spring-boot-starter-web
的Spring项目。
一切都运作良好,但我想使用@JsonIgnore
注释从域对象中排除一些字段。这不起作用。我检查了两个:com.fasterxml.jackson.annotation.JsonIgnore
和org.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.codehaus
或com.fasterxml
中的任何类(我只尝试在一个地方使用@JsonIgnore
)。在我看来,我应该摆脱双倍的实施,并让oAuth
使用com.fasterxml
。但我不确定这是一条好路,如何实现呢?
我试图建立https://spring.io/guides/gs/accessing-data-rest/
并使用@JsonIgnore
并且它在那里工作,但是mvn dependency:tree
只显示了杰克逊映射器的一个实现(com.fasterxml
)。
有人可以帮我吗?
晚上好,
我找到了@JsonIgnore
无效的原因。这是一个错字:(
我从大写字母开始私人领域:
@JsonIgnore
private String Roles;
将其更改为
@JsonIgnore
private String roles;
它开始工作了。当然我必须使用适当的@JsonIgnore
实现,在这种情况下它是com.fasterxml.jackson.annotation.JsonIgnore
很抱歉发布此问题。一切都很好。我是瞎子。