We're using Spring MVC and jackson parser (for java objects to json).
We have 2 entities (with many-to-many relationship):
- Project
- Service
Project contains list of services, and Service contains list of project.
We've an ajax call to the Controller which fetch the Project by its name, and also its services. Everything looks ok meanwhile.
The problem is when jackson parse the services list to json. This is the result:
[{"name":"CreateAccount","hebName":"ABC","projects":
[{"id":2,"name":"yesTouch","displayName":"ABC","authorizedUsers":[],"authorizedGroups":
[],"services":["CreateAccount",{"name":"RBMHotbill","hebName":"ABC","projects":[2]}]}]},
<b>"RBMHotbill"</b>]
What hapeens is that each service displayed fully one time and the other time only its name.
Here are snippets of the Entities and the Controller's method:
@Entity
@Table (name = "GOBLIN_SERVICES")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="name")
public class Service implements Serializable {
private static final long serialVersionUID = 8694874911004747694L;
@Id
@Column (name = "PROXY_NAME", nullable = false)
private String name;
@ManyToMany(mappedBy="services")
private List<Project> projects = new ArrayList<Project>();
@Entity
@Table (name = "GOBLIN_PROJECTS")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Project implements Serializable {
private static final long serialVersionUID = -666638801643613543L;
@Id
@GenericGenerator(name="generator", strategy="increment")
@GeneratedValue(generator="generator")
@Column (name = "PROJECT_ID", nullable = false)
private long id;
@ManyToMany
@JoinTable(name = "GOBLIN_SERVICES_PROJECTS", joinColumns = {
@JoinColumn(name = "PROJECT_ID", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "PROXY_NAME",
nullable = false, updatable = false) })
private List<Service> services = new ArrayList<Service>();
@RequestMapping(value="/services/list", method=RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Service> getServicesByProjectName(Locale locale, Model model, String projectName) {
// Get Project
Project project = projectDao.getProjectByName(projectName);
List<Service> services = project.getServices();
return services;
}
Any ideas ?
Thanks, Tal.