Search code examples
javaarraysjsonjsonschema2pojo

How to create POJO class with different structure JSON Object


Here is my json schema

[
 {
  "title": "Taman Lansia",
  "alamat": "Jl. Cisangkuy, Citarum, Bandung Wetan, Kota Bandung, Jawa Barat 40123",
  "image": "Link image",
  "status": 1
 },
 {
  "title": "Fasilitas Taman_Lansia",
  "fasilitas": [
    {
     "namaFasilitas": "Area Piknik",
     "imageFasilitas": "Link Image"
    },
    {
     "namaFasilitas": "Jalur Jogging",
     "imageFasilitas": "Link Image"
    }
   ],
   "status": 2
 }
]

How to resolve this, because i'm just trying in http://jsonschema2pojo.org and then no result or no response. Thank you


Solution

  • Well you POJO obviously has to have every possible attribute you have in your schema and then just have the other values not set as null...

    So

    public class MyObject {
        private String title;
        private List<OtherObject> fasilitas;
    ...
    
    }