Error - JSON getting into infinite loop

痴心易碎 提交于 2019-12-12 02:53:09

问题


I am trying to display JSON data, for that i am using fasterxml jackson. I am able display JSON but the JSON is getting to infinite loop and in log file i am getting error as

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/EAD].[spring]] (http--127.0.0.1-8080-1) Servlet.service() for servlet spring threw exception: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonMappingException$Reference from [Module "deployment.EAD.war:main" from Service Module Loader]

Here is my controller method.

@RequestMapping("/viewDashboard")
@ResponseBody
public ModelMap test(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestParam String name) {

    ModelMap modelMap = new ModelMap();
    List<Instances> instances = viewDashboardServiceImpl.viewDashboard();
    return modelMap.addAllAttributes(instances);

}

Actually my Instance.java is having relation with Application.java and Environment.java

Following are my model.java

Here is my instance.java

@Id
@GeneratedValue
@Column(name = "instanceId")
private long id;

@Column(name = "name")
private String instanceName;

@ManyToOne
@JoinColumn(name = "appId")
private Applications applications;

@ManyToOne
@JoinColumn(name = "enviId")
private Environments environments;

@Column(name = "version")
private String version;

Here is my Application.java

    @Id
@GeneratedValue
@Column(name = "appId")
private long id;

@Column(name = "name")
private String name;

@Column(name = "ownerName")
private String ownerName;

@Column(name = "version")
private String version;

@OneToMany(mappedBy = "applications", targetEntity = Instances.class)
private Set<Instances> instances;

Here is my Environment.java

@Id
@GeneratedValue
@Column(name = "enviId")
private long id;

@Column(name = "name")
private String name;

@Column(name = "ownerName")
private String ownerName;

@Column(name = "version")
private String version;

@OneToMany(mappedBy = "environments", targetEntity = Instances.class)
private Set<Instances> instances;

Here is my JSON

{"instances":{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":{"id":1,"name":"SAP","ownerName":"Mou","version":"3.2.1abc","instances":[{"id":2,"instanceName":"SAP BW DEV1","applications":

As above JSON keeps going on with repeated data. I am having following dependency in maven also.

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.5</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.4.5</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.4.5</version>
    </dependency>

And i have added following snippet in servlet.xml also.

    <bean id="contentNegotiationManager"
    class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="false" />
    <property name="favorParameter" value="true" />
    <property name="mediaTypes">
        <value>
            json=application/json
            xml=application/xml
        </value>
    </property>
</bean>

来源:https://stackoverflow.com/questions/36619521/error-json-getting-into-infinite-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!