Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring引导-实体到json-递归_Json_Spring_Hibernate_Jackson - Fatal编程技术网

Spring引导-实体到json-递归

Spring引导-实体到json-递归,json,spring,hibernate,jackson,Json,Spring,Hibernate,Jackson,我有相互双向映射的实体。调用REST Http.GET请求从db获取所有记录,由于无限递归,我收到StackOverflowException。我试图以不同的组合使用@JsonIgnore、@JsonBackReference、@JsonManageReference和@JsonIdentityInfo,但没有得到积极的结果。我仍然收到这个错误 Spring Boot在2.6.6版中加载了我的jackson 这是我的基本实体: @MappedSuperclass public class Bas

我有相互双向映射的实体。调用REST Http.GET请求从db获取所有记录,由于无限递归,我收到StackOverflowException。我试图以不同的组合使用@JsonIgnore、@JsonBackReference、@JsonManageReference和@JsonIdentityInfo,但没有得到积极的结果。我仍然收到这个错误

Spring Boot在2.6.6版中加载了我的jackson

这是我的基本实体:

@MappedSuperclass
public class BaseEntity {
    @Id
    @GeneratedValue
    private Long id;
    private String createdBy;
    private Date createdOn;
    private String modifiedBy;
    private Date modifiedOn;
    public String description;

    public BaseEntity() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Date getModifiedOn() {
        return modifiedOn;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
第一类实体:

@Entity
public class Entry extends BaseEntity{

    private Date businessOperationDate;

    @ManyToOne
    private Version version;

    @ManyToOne
    private Status status;

    @ManyToOne
    @JsonManagedReference
    private Account account;

    public Entry() {
    }

    public Date getBusinessOperationDate() {
        return businessOperationDate;
    }

    public void setBusinessOperationDate(Date businessOperationDate) {
        this.businessOperationDate = businessOperationDate;
    }

    public Version getVersion() {
        return version;
    }

    public void setVersion(Version version) {
        this.version = version;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }
}
第二个:

@Entity
public class Account extends BaseEntity{
    private String number;

    @OneToMany(mappedBy = "account", fetch = FetchType.EAGER)
    @JsonBackReference
    private List<Entry> entries;

    @ManyToMany(mappedBy = "accounts")
    private List<Project> projects;

    public Account() {
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public List<Entry> getEntries() {
        return entries;
    }

    public void setEntries(List<Entry> entries) {
        this.entries = entries;
    }

    public List<Project> getProjects() {
        return projects;
    }

    public void setProjects(List<Project> projects) {
        this.projects = projects;
    }
}
pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>test2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>test2</name>
    <description>test2</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-security</artifactId>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
            <version>9.4-1201-jdbc41</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- model mapper -->
        <dependency>
            <groupId>ma.glasnost.orika</groupId>
            <artifactId>orika-core</artifactId>
            <version>1.4.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
com.test
测试2
0.0.1-快照
罐子
测试2
测试2
org.springframework.boot
spring启动程序父级
1.3.5.1发布
UTF-8
1.8
org.springframework.boot
弹簧靴起动器执行器
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
SpringBootStarterWeb
org.postgresql
postgresql
运行时
9.4-1201-jdbc41
org.springframework.boot
弹簧起动试验
测试
奥里卡大学
奥里卡岩芯
1.4.6
org.springframework.boot
springbootmaven插件

请告诉我,我做错了什么。我希望在结果中只接收一个级别,例如,调用getAll()作为条目,我希望接收包含与帐户相关的信息的所有条目,反之,调用getAll()作为帐户。

我搜索了更多次此错误,但是我可以遇到任何我得到的错误情况,我通过在一些关系映射中添加注释
@JsonIgnore
来纠正它

这就是一个例子

  @ManyToMany(mappedBy = "accounts")
    @JsonIgnore
    private List<Project> projects;
@ManyToMany(mappedBy=“accounts”)
@杰索尼奥雷
私人清单项目;

我搜索了更多次此错误,但我可以遇到此错误案例中的任何问题,我通过在某些关系映射中添加注释
@JsonIgnore
来更正它

这就是一个例子

  @ManyToMany(mappedBy = "accounts")
    @JsonIgnore
    private List<Project> projects;
@ManyToMany(mappedBy=“accounts”)
@杰索尼奥雷
私人清单项目;

请发布您的pom.xml,请从他们的文档中检查spring boot公共属性文件中的json响应。另外,您已经在pom.xml中为Jackson绑定错误添加了一个排除项。感谢您的支持。请发布您的pom.xml,请从他们的文档中检查spring boot公共属性文件中的json响应。另外,您已经在pom.xml中为Jackson绑定错误添加了一个排除项。谢谢你的支持。假设,我想从帐户中获取一个字段。我现在能做什么?好的。假设,我想从帐户中获取一个字段。我现在能做什么?