google-gson 实现java object和json串之间的转换 | 张恒镭的博客

google-gson 实现java object和json串之间的转换

时间:14-07-15 栏目:java编程 作者:恒镭, 张 评论:0 点击: 2,023 次

前言:

官方网站:http://code.google.com/p/google-gson/

google-gsonA Java library to convert JSON to Java objects and vice-versa

Gson是一个实现吧Java Objects序列化为JSON的一个工具类。当然也可以把JSON反转成JAVA了obj。甚至没有Java类的源代码也能实现转换。

Gson is a Java library that can be used to convert Java Objects into their representation. It can also be used to convert a string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.

There are a few open-source projects that can convert Java objects to JSON. However, most of them require that you place Java annotations in your classes; something that you can not do if you do not have access to the source-code. Most also do not fully support the use of Java Generics. Gson considers both of these as very important design goals.

Gson Goals

  • Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa

  • Allow pre-existing unmodifiable objects to be converted to and from JSON
  • Extensive support of Java Generics
  • Allow custom representations for objects
  • Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)

Gson Documentation

  • Gson API: Javadocs for the current Gson release

  • Gson user guide: This guide contains examples on how to use Gson in your code.
  • Gson Roadmap: Details on upcoming releases
  • Gson design document: This document discusses issues we faced while designing Gson. It also include a comparison of Gson with other Java libraries that can be used for Json conversion

Please use the google-gson Google Group to discuss Gson, or to post questions.

 

具体使用

参考:http://www.cnblogs.com/cyjch/archive/2012/02/15/2352792.html

声明: 本文由( 恒镭, 张 )原创编译,转载请保留链接: google-gson 实现java object和json串之间的转换

google-gson 实现java object和json串之间的转换:等您坐沙发呢!

发表评论




------====== 本站公告 ======------
欢迎关注我的博客。

其他