详解json string转换为java bean及实例代码
pom中添加如下两个库:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<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的定义为:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
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;
}
}
|
测试用例为:
?
1
|
ESMetaDataInfoIndex dataInfo = JSON.parseObject(json.toJSONString(),ESMetaDataInfoIndex . class );
|
以上就是json string转换为java bean的实例,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://www.jianshu.com/p/d4428c1b83fb
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 21
-
2025-05-26 37
-
2025-05-25 87
-
2025-05-27 79
-
2025-05-29 79
热门评论