jeudi 1 juillet 2021

Using JAVA Reflection how to create custom JSON object mapping

I have a json Object in the below format, I need to assign the values from Json to java object, But the label name in JSON and class is different.

{
  FirstName: "Sample",
  LastName: "LName",
  Address: [
    {
      type: "Temp",
      street: "test stree",
      
    },
    {
      type: "Perm",
      street: "test stree",
      
    }
  ]
}

Class Parent{

private String Name1;
private String Nama2;
private List<Address> address;}

Class Address{

Private String type;

private String data;
}

I wanted to implement the custom object mapper using Java reflection. the mapping is as below, But I am not getting idea to implement this, Any valuable suggestion or usage of external api would help me to achieve the scenario.

Json Object name Jave Class object Name FirstName ---------- Name1 LastName ---------- Name2
Address.type ------- Address class type Address.street ----- Address class data





Aucun commentaire:

Enregistrer un commentaire