Use Variables in JSON and deserialize in POJO based on section

111 Views Asked by At

I have defined an example JSON below-

{ "common" : {
   "data" : [ {
     "ref" : "data1"
     "x" : "${variable1}",
     }, { 
     "ref" : "data2"
     "y" : "${variable2}"
     }
   ]
  },
  "section1" : {
     "variables" : {
       "${variable1}" : "var1_section1",
       "${variable2}" : "var2_section1",
  
     },
     "data" : ["data1", "data2"]
  
  },
  "section2" : {
     "variables" : {
       "${variable1}" : "var1_section2"
       "${variable2}" : "var2_section2",
     },
     "data" : ["data1", "data2"]
  }
}

I have a common section and two more sections (section1 and section2). Data which is common for both sections is defined in the common section. I have to deserialize this JSON into a POJO. Based on the section which will be passed as a parameter, the value of the variables should be deserialized for those sections. If I pass section1 as the parameter, the data should look like-

data : [ "x" : "var1_section1", "y" :"var2_section1" ]

And if I pass section2 as the parameter, the data should look like-

data : [ "x" : "var1_section2", "y" :"var2_section2" ]

I want to know if this is achievable using any JSON annotations in Java?

0

There are 0 best solutions below