资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

详解jsonstring转换为javabean及实例代码

详解json string转换为java bean及实例代码

成都创新互联专业为企业提供天元网站建设、天元做网站、天元网站设计、天元网站制作等企业网站建设、网页设计与制作、天元企业网站模板建站服务,10年天元做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

pom中添加如下两个库:


  org.codehaus.jackson 
  jackson-core-asl
  1.9.2
  provided



  com.alibaba 
  fastjson
  1.2.7
  provided


java bean的定义为:

package test.fastjson;

import java.util.HashMap;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

//简单地忽略掉从JSON(由于在应用中没有完全匹配的POJO)中获得的所有“多余的”属性
@JsonIgnoreProperties(ignoreUnknown = true)
public class ESMetaDataInfoIndex  
{
  //改变某个成员属性所使用的JSON名称
  @JsonProperty("tableStrategy")
  private String tableStrategy = null;
  @JsonProperty("indexName")
  private String indexName = null;
  @JsonProperty("topic")
  private String topic = null;
  @JsonProperty("nameSpace")
  private String nameSpace = null;
  @JsonProperty("extendAttr")
  private Map extendAttr = new HashMap();
  @JsonProperty("type")
  private String type = null;
  @JsonProperty("ttl")
  private int ttl = 0;
  @JsonProperty("splitCol")
  private String splitCol = null;


  /**
  **/
  public String getTableStrategy() 
  {
    return tableStrategy;
  }
  public void setTableStrategy(String tableStrategy) 
  {
    this.tableStrategy = tableStrategy;
  }

  /**
  **/
  public String getIndexName() 
  {
    return indexName;
  }
  public void setIndexName(String indexName) 
  {
    this.indexName = indexName;
  }

  /**
  **/
  public String getTopic() 
  {
    return topic;
  }
  public void setTopic(String topic) 
  {
    this.topic = topic;
  }

  /**
  **/
  public String getNameSpace() 
  {
    return nameSpace;
  }
  public void setNameSpace(String nameSpace) 
  {
    this.nameSpace = nameSpace;
  }

  /**
  **/
  public Map getExtendAttr() 
  {
    return extendAttr;
  }
  public void setExtendAttr(Map extendAttr) 
  {
    this.extendAttr = extendAttr;
  }

  /**
  **/
  public String getType() 
  {
    return type;
  }
  public void setType(String type) 
  {
    this.type = type;
  }

  /**
  **/
  public int getTtl() 
  {
    return ttl;
  }
  public void setTtl(int ttl) 
  {
    this.ttl = ttl;
  }

  /**
  **/
  public String getSplitCol() 
  {
    return splitCol;
  }
  public void setSplitCol(String splitCol) 
  {
    this.splitCol = splitCol;
  }   
}

测试用例为:

ESMetaDataInfoIndex dataInfo = JSON.parseObject(json.toJSONString(),ESMetaDataInfoIndex .class);

以上就是json string转换为java bean的实例,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


网站标题:详解jsonstring转换为javabean及实例代码
标题链接:http://cdkjz.cn/article/jchogo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220