詳解jsonstring轉(zhuǎn)換為javabean及實例代碼

詳解json string轉(zhuǎn)換為java bean及實例代碼

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供天元網(wǎng)站建設(shè)、天元做網(wǎng)站、天元網(wǎng)站設(shè)計、天元網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、天元企業(yè)網(wǎng)站模板建站服務(wù),10年天元做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

pom中添加如下兩個庫:

<dependency>
  <groupId>org.codehaus.jackson </groupId>
  <artifactId>jackson-core-asl</artifactId>
  <version>1.9.2</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>com.alibaba </groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.7</version>
  <scope>provided</scope>
</dependency>

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(由于在應(yīng)用中沒有完全匹配的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<String, String> extendAttr = new HashMap<String, String>();
  @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<String, String> getExtendAttr() 
  {
    return extendAttr;
  }
  public void setExtendAttr(Map<String, String> 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轉(zhuǎn)換為java bean的實例,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

網(wǎng)站標題:詳解jsonstring轉(zhuǎn)換為javabean及實例代碼
文章URL:http://muchs.cn/article10/jchogo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷網(wǎng)站收錄、網(wǎng)站制作、網(wǎng)站改版、動態(tài)網(wǎng)站網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)