Json deserialize with references in Java



I am trying to create java objects from json files. Lets say I have two classes:



Class Parent{
int parentId;
.....
.....
Child c;

public Parent(int parentId, Child c){
this.parentId = parentId;
this.c = c;
}

Class Child{
int childId;
.....
.....

public Child(int childId){
this.childId = childId;
}

Child child = new Child(10);
Parent p = new Animal(1,child);


Now imagine I have two json files:



Parents.json: {"parentId":"1","child":10 ......}
Children.json: {"childId":10, ...... }


Are there any java libraries that let me get back the original 'p' (Parent) object from these two files?


Also does xml libraries have better unmarshalling capablilites using references than json? In this scenario, would it be easier to represent data in xml and then try to unmarshall the data?


No comments:

Post a Comment