Heim  >  Artikel  >  Java  >  Beispielanalyse zur Konvertierung eines JSON-Strings in eine Java Bean

Beispielanalyse zur Konvertierung eines JSON-Strings in eine Java Bean

黄舟
黄舟Original
2017-07-26 15:21:192170Durchsuche

Dieser Artikel stellt hauptsächlich die detaillierte Erklärung der JSON-String-Konvertierung in Java Bean und die relevanten Informationen des Beispielcodes vor. Hier ist der Beispielcode, auf den sich Freunde in Not beziehen können >Detaillierte Erklärung der JSON-String-Konvertierung Fügen Sie der Java-Bean und dem Beispielcode die folgenden zwei Bibliotheken hinzu

pom:


Die Definition von Java Bean ist:
<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>


Der Testfall ist:
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<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;
  }   
}

Das obige ist der detaillierte Inhalt vonBeispielanalyse zur Konvertierung eines JSON-Strings in eine Java Bean. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn