question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'@JsonIgnoreProperties' not working with entity relationship in version 2.9.5 and spring-boot 2.0.1

See original GitHub issue

Hi. 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Apr 24, 2018

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 😃

0reactions
cowtowncodercommented, Apr 25, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found