简体   繁体   English

如何将多态json字符串转换为Java bean类

[英]How to convert polymorphic json string to java bean class

How can i map json to bean class with polymorphic data type i have three pattern of json statement 我如何将json映射到具有多态数据类型的bean类,我有三种json语句模式

{
  actor:"ashok",
  verb:"completed"
} 

or this 或这个

  {
      actor:["ashok","kumar"],
      verb:{
          disp:"en-us",
          url:{
             link:"url",
             tag:"tagname"
          }
      }
  } 

or 要么

{
      actor:{name:["ashok","kumar"],mail:["a@a.com","b@b.com"]}
      verb:{
          disp:"en-us",
          url:{
             link:"url",
             tag:"tagname"
          }
      }
  } 

how can i map all these type of json in same bean class. 我如何在同一bean类中映射所有这些类型的json。 i need a polymorphic bean class which can handle all type of objects of json and also able to handle single sting data 我需要一个多态bean类,它可以处理所有类型的json对象,并且还可以处理单个字符串数据

you can use the Gson. 您可以使用Gson。 it provide fromJson() method. 它提供fromJson()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM