I am new to this Jackson serialization and deserialization. I have researched a lot of links for my issue ,didn't find any. So I am posting it here . Please help!
I have a three classes(entities) which i want to serialize and deserialize:
MyStackClass and MyService class are mapped by MyServiceMapping class.
public class MyStackClass implements Serializable, Entity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID")
private int id;
@OneToMany
private List<MyserviceMapping> services;
}
public class MyserviceMapping implements Serializable,Entity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@ManyToOne
private MyStackClass myStackClass;
@ManyToOne
private MyService myService;
}
public class MyService implements Entity{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int myServiceId;
@OneToMany
private List<MyServiceMapping> myServices;
}
Now when i serialize MyStackClass: the json generated is like:
{
"id":1,
"services":[
{"myService":
{
"myServiceId":27
}
},
{"myService":
{
"myServiceId":3
}
}
]
}
But my client says that this is not upto the response guidleines. The json should not have extra myService tag inside the list,as it is already understood that this is a list of services . it should look like :
{
"id":1,
"services":[
{"myServiceId":27},
{"myServiceId":3}
]
}
I have tried some solutions but nothing worked.I do not want to go into manually setting the json ,I am looking at a clean jackson approach.
Thanks in advance!