'@JsonIgnoreProperties' not working with entity relationship in version 2.9.5 and spring-boot 2.0.1
See original GitHub issueHi. I’m using jackson 2.9.5 (spring-boot 2.0.1) and getting some issue when trying to use @JsonIgnoreProperties in a relationship.
Example:
@Entity
public class Login {
String email;
String password;
}
@Entity
public class User {
String name;
Company company;
@JsonIgnoreProperties({"password"})
Login login;
}
I didn’t know that @JsonIgnoreProperties could be used that way, but recently reading I saw that it works. When I try to get one user, the generated JSON should be:
{
name: "User",
login: {
email: "test@test.com"
}
}
But getting the password (that should be ignored) too:
{
name: "User",
login: {
email: "test@test.com",
password: "test"
}
}
When I’m working with Bidirectional relationship it gets worse, because I get error of infinite recursion when trying to get the Company, for example. Example:
@Entity
public class Company {
String name;
@JsonIgnoreProperties({"company"})
List<User> userList;
}
First time working with spring-boot here, maybe I can have misunderstood but I’ve read about this kind of use in Issue 70 and Issue 133.
I tried with jackson 2.9.4 (spring-boot 2.0.0) and it didn’t work too.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:12 (5 by maintainers)
Top Results From Across the Web
JsonIgnoreProperties not working with spring boot
Put @JsonIgnoreProperties on a class you deserialize, and not in Spring controller. However, I see that the class you want to deserialize is...
Read more >Jackson @JsonIgnore, @JsonIgnoreProperties and ...
In this tutorial, I show you how to ignore certain fields when serializing an object to JSON using Jackson @JsonIgnore, @JsonIgnoreProperties and ...
Read more >Grails Diary - RSSing.com
The release upgrades Spring Boot to 1.2.6, and there are a lot of other fixes included, ... The release also fixed a problem...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also, as per my edit above: you are right, annotation DOES actually work. I love it when I sometimes forget that a feature enhancement has been made to support use case that did not work earlier 😃
@robsonfar Ok good. If it makes no difference it makes no difference. Thank you for testing it. I just wanted to know if it might be relevant, given that framework will either have to work with declared type or use Type Erased instance type – and in either case lose some information (in fact the Right Way is to combine the two… but I digress 😃 ).
I hope Spring Boot folks can share light here. It is possible something is needed from Jackson side, but they are in better position to help troubleshoot first, I think.