json

The json framework for java.(java 序列化反序列化工具。)

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.github.houbb
ArtifactId

ArtifactId

json
Last Version

Last Version

0.1.9
Release Date

Release Date

Type

Type

jar
Description

Description

json
The json framework for java.(java 序列化反序列化工具。)

Download json

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.houbb/json/ -->
<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>json</artifactId>
    <version>0.1.9</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.houbb/json/
implementation 'com.github.houbb:json:0.1.9'
// https://jarcasting.com/artifacts/com.github.houbb/json/
implementation ("com.github.houbb:json:0.1.9")
'com.github.houbb:json:jar:0.1.9'
<dependency org="com.github.houbb" name="json" rev="0.1.9">
  <artifact name="json" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.houbb', module='json', version='0.1.9')
)
libraryDependencies += "com.github.houbb" % "json" % "0.1.9"
[com.github.houbb/json "0.1.9"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.houbb : heaven jar 0.1.86
com.github.houbb : asm-tool jar 0.0.3

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
com.alibaba : fastjson jar 1.2.62

Project Modules

There are no modules declared in this project.

json

json 是 java 实现的序列化 json 框架。

Maven Central

特性

  • 8 大基本类型支持

  • 基本类型/对象数组/集合/枚举/对象 支持

  • 极简的 API

为何创作

  • 解决 fastJson 中的不足

FastJSON 在序列化本身存在一定限制。当对象中有集合,集合中还是对象时,结果不尽如人意。

  • 轻量且高效

FastJson 等 json 工具特性丰富,但是考虑过多,也兼容过多。

希望通过严格控制序列化和反序列,从而使得代码变得高效轻量,更加适合自己的使用场景,

  • 后续拓展

后续序列化相关,将使用这个工具实现,方便自行拓展学习。

变更日志

变更日志

快速开始

环境依赖

JDK 1.7+

Maven 3.X

maven 依赖

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>json</artifactId>
    <version>${最新版本}</version>
</dependency>

基本例子

序列化

int[] ints = new int[]{1,2,3};
String json = JsonBs.serialize(ints);
Assert.assertEquals("[1,2,3]", json);

反序列化

final String json = "[1,2,3]";
int[] ints = new int[]{1,2,3};
Assert.assertArrayEquals(ints, JsonBs.deserialize(json, int[].class));

反序列化列表

final String json = "[1,2,3]";
List<Integer> integerList = JsonBs.deserializeArray(json, Integer.class);
Assert.assertEquals(3, integerList.size());

更多特性

序列化是否保留 null 值

  • 说明

默认 null 值不保留。

  • 测试代码
Book book = new Book();

String json = JsonBs.serialize(book);
Assert.assertEquals("{}", json);

final ISerializeConfig config = SerializeConfig.newInstance().nullRemains(true);
String nullJson = JsonBs.serialize(book, config);
Assert.assertEquals("{\"name\":null}", nullJson);
  • Book.java
public class Book {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

是否基于 field

  • 说明

默认基于 field 进行序列化和反序列化处理。

当然如果不指定,则以方法为准。

  • 测试代码
NotFieldBook book = new NotFieldBook();
book.setName("hello");

final String json = "{\"name\":\"hello\"}";
Assert.assertEquals(json, JsonBs.serialize(book, SerializeConfig.newInstance().fieldBased(false)));

final IDeserializeConfig deserializeConfig = DeserializeConfig.newInstance().fieldBased(false);
NotFieldBook book2 = JsonBs.deserialize(json, NotFieldBook.class, deserializeConfig);
Assert.assertEquals("hello", book2.getName());
  • NotFieldBook.java
public class NotFieldBook {

    private String bookName;

    public String getName() {
        return bookName;
    }

    public void setName(String name) {
        this.bookName = name;
    }
}

Versions

Version
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1