【问题标题】:How to create POJO class with different structure JSON Object如何创建具有不同结构 JSON 对象的 POJO 类
【发布时间】:2019-06-13 08:01:24
【问题描述】:

这是我的 json 架构

[
 {
  "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
 }
]

如何解决这个问题,因为我只是在http://jsonschema2pojo.org 中尝试,然后没有结果或没有响应。 谢谢

【问题讨论】:

  • 这不是真正的 json 架构,正如您在链接的网站上看到的那样,他们想要像 { "type":"object", "properties": { "foo": { "type": "string " }, "bar": { "type": "integer" }, "baz": { "type": "boolean" } } }

标签: java arrays json jsonschema2pojo


【解决方案1】:

那么你的 POJO 显然必须在你的架构中拥有所有可能的属性,然后只将其他值不设置为 null...

所以

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

}

【讨论】:

  • 感谢您的回答,非常感谢您解决问题
猜你喜欢
  • 2013-04-25
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
相关资源
最近更新 更多