-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'@JsonIgnore' annotation not working with creator properties, serialization #1317
Comments
@rajanya I am not aware of any intended changes, so I would need a reproduction (ideally simple unit test) to show what kind of usage is negative affected. |
I am building a project using Spring Boot and JPA+Hibernate. This is an example of JPA many-to-many mapping using Sprint Boot and MySQL. I have used Lombok for getter and setter.
The caller:
Error with Jackson 2.8.1: (This error is not coming with Jackson 2.4.4)
Please let me know if the example is clear and sufficient. |
Unfortunately that is not quite enough to reproduce the problem; especially if So I would really need a stand-alone reproduction; POJO declaration looks ok to me, and basic ignoral handling has no known problems at this point. |
I have the same problem when upgrading from 2.6.3 to version 2.7.0 and upwards (tested up to 2.8.2). |
@clubshrimp Nonetheless I can not reproduce this without an actual example, ideally without Lombok or Hibernate. If Hibernate is required part, bug needs to be filed for |
Yes, I can imagine it's hard to reproduce without an actual example. Sorry for that. I don't know Jackson well enough to figure out how to write a stand-alone reproduction, but if I figure it out, I will certainly post it here! |
I just tested with 2.6.7, and it works fine as well, so the issue appeared between 2.6.7 and 2.7.0. |
@clubshrimp My guess is that this could be related to addition of handling of Note on Hibernate: the original report definitely is related to Hibernate, since |
My report is also related to Hibernate; I was just saying that I didn't use jackson-datatype-hibernate module (it didn't seem necessary) I haven't used @ConstructorProperties in my code, and didn't have jackson-datatype-jdk7 either.
The trace is
The currency class is: import com.fasterxml.jackson.annotation.JsonIgnore;
import forex.trading.entity.Position;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;
@Entity
@NoArgsConstructor
@Builder
@AllArgsConstructor
@EqualsAndHashCode(of = {"id", "tradingActive"})
@ToString(includeFieldNames = false, of = {"id", "tradingActive"})
@Table(catalog = "fxcommon")
@Getter
@Setter
public class Currency {
@Id
@Column(name = "Code", nullable = false, length = 3)
private String id;
@JsonIgnore
@Column(name = "TradingActive")
private boolean tradingActive;
@JsonIgnore
@OneToMany(mappedBy = "currency")
@Cascade(CascadeType.ALL)
private Set<Country> countries = new HashSet<>();
@JsonIgnore
@OneToMany(mappedBy = "baseCurrency")
private Set<Position> positionsBase;
@JsonIgnore
@OneToMany(mappedBy = "quoteCurrency")
private Set<Position> positionsQuote;
public Currency(String idParam, boolean tradingActiveParam) {
id = idParam;
tradingActive = tradingActiveParam;
}
} |
@clubshrimp Hibernate usage is often crucial, although question is whether it is required or not. More often than not it is, esp. so if hibernate module is not used: Hibernate uses proxy types ( At any rate, what I would need to work on this would be a reproduction:
I am guessing (2) is the most likely route. |
Good point, I should have used jackson-datatype-hibernate from the beginning even if I had no problem without it until 2.7.
I haven't seen any reference in the javadoc for @JsonIgnore whether the property should actually be present in the Json but with a null value. I think "ignored" means it should not be there. If that is not normal as I suppose, I need to see if I can run the test without lombok on the Currency class... |
As a workaround you can use @JsonIgnoreProperties instead @JsonIgnore. That works for me)) |
@cowtowncoder I recently ran into the same issue when upgrading to new version (same persisten bag stack overflow exception like in first post). After some digging I've managed to pinpoint the issue to @AllArgsConstructor usage, specificlly its usage of @ConstructorProperties. Here is a failing test that replicates this issue:
If @ConstructorProperties is removed, test passes. I've also went back through jackson versions and noticed that this issue started happening in 2.7.0. version. Prior to this version, the test above passes |
@kajo-bellabeat Hmmh. That is tricky, as this would become split-annotation case... due to That is to say, I am not 100% sure behavior is incorrect in that regard, considering semantic of |
Experiencing the same problem after updating from 2.5.3 to 2.8.5. We use spring framework. @JsonIgnore and @JsonIgnoreProperties are not working anymore. |
@cowtowncoder do you have any ideas? This is the file and the annotations that were working prior to moving to 2.8.5 after which Update: looks like it's a conflict since Spring 3.1.3 still uses an older version of fasterxml which is causing the annotations to be ignored now. Fixed forcing Spring to use Fasterxml 2. |
@tarelli At this point I am only going to look into this if there is a self-contained unit test that does not rely on external dependencies (like Spring or Hibernate or Lombok). In case of code generation (like Lombok), that would need to include generated classes. Note, too, that if you say there's a |
Looks like test by @kajo-bellabeat might work, so let me have another look here. |
Ok. I can reproduce the issue, and looking into it, I think the problem is that property collector considers this a "split" case (one where ignoral AND inclusion are specified via annotations). This should not occur, in a way, since individual properties are NOT explicitly included but as a set. I'll see if I can figure out how to fix this case. |
It happens the same problem with "spring-boot-starter-data-jpa". The version as follow: <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.5.RELEASE</version>
</dependency> It happens cause by the “@RestController” and "@responsebody" annotion In SpringMVC. This problem causes some problems In My solution as follow: |
I am using Spring 3.3.4 and experiencing the issue. has anyone found the solution?
when i call findUserWithWallets() with correct values i run into stackoverflowerror. I have tried to use many things. Nothing works |
Please file a new issue with Jackson-ONLY reproduction otherwise consult with Spring/SpringBoot team first |
Also: handling of creator properties has improved over versions, and in particular latest work for 2.18 may have resolved some older problems -- so testing with 2.18.0-rc1 makes sense (Spring Boot typically works with wide range of Jackson versions so it is often possible to override Jackson version in use). |
I found a solution actually. The problem with Kotlin data class is that Kotlin generates a toString. The toString method of UserWallet was calling the toString of User and the vise versa. This leads to infinite calls. Unfortunately, it took me time to realize that. This happens on in Kotlin code. In Java code it does not. The solution was override the ToString like below
This toString method can be put in one of the classes. |
Thank you for sharing @molorane. SOE is such a general thing with many possibilities as to root cause so it's quite likely that what you had is different from OP and others. |
My code having @JsonIgnore annotation is working fine with version 2.4.4 but it stopped working when I upgraded to version 2.8.1. I am getting "Infinite recursion (StackOverflowError)" only with 2.8.1 version.
The text was updated successfully, but these errors were encountered: