spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
916 stars 562 forks source link

@JsonIgnoreProperties("filed") annotations are not respected by NestedEntitySerializer [DATAREST-1236] #1596

Open spring-projects-issues opened 6 years ago

spring-projects-issues commented 6 years ago

Phil Webb opened DATAREST-1236 and commented

Originally raised as a spring boot issue along with a project that shows the issue it appears that the @JsonIgnoreProperties("field") annotation is currently being ignored by Spring Data Rest.

After a bit of digging I think it is due to the custom NestedEntitySerializer. Specifically this line which serializes the value without providing Jackson access to the field annotations


1 votes, 6 watchers

spring-projects-issues commented 6 years ago

Robson Farias commented

Hi, just a small correction, the Jackson annotation is @JsonIgnoreProperties("field"). @JsonIgnore works ok. Thanks for raising this issue!

spring-projects-issues commented 6 years ago

Phil Webb commented

Robson Farias Thanks, I've edited the description

spring-projects-issues commented 6 years ago

Oliver Drotbohm commented

Hm, I'm not sure the serializer is the place to fix this. TBCH, I wouldn't even have expected the serializer to be triggered for a property that's marked as ignored as I assumed Jackson to calculate the list of properties to serialize first and only trigger serializers for the ones that survive the filtering. I'd have to check whether our custom BeanSerializerModifier messes this up

spring-projects-issues commented 5 years ago

Brian Strom commented

This one has been out for a while and seems to be understood pretty well. Any chance of getting some attention to it? JsonIgnoreProperties is a particularly helpful annotation. (to me at least!)

spring-projects-issues commented 4 years ago

deftdawg commented

I've spent a couple of days trying to figure out why fields marked as JsonIgnoreProperties like this:

@ManyToOne
@JsonIgnoreProperties(value = "myclass", allowSetters = true)
private Company customer;    

are effectively attempting to serialize my entire database and return it in the JSON value in my ResponseEntity.    JsonIgnoreProperties supposed to prevent that recursion through object relationships when serializing to JSON.    It's good to know that maybe the problem is not what I'm doing, but rather the underlying implementation is broken.   Does anyone have a good approach/example for returning objects with complicated relationships where those are properly swapped out for HATEOAS links so ResponseEntity's can be used?   I can't find anything that's anywhere near current that works (most code I've found refers to Resource and stuff like that that has been replaced since spring-hateoas 1.0).  

HashirLabs commented 1 year ago

any progress on this, this is very random that it works in one project for me while it does not in the other, the target property i am try to ignore is of type Set.