com.github.houbb:json-core

The json framework for java.

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.github.houbb
ArtifactId

ArtifactId

json-core
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

The json framework for java.

Download json-core

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
com.github.houbb : json-api jar 0.0.1
com.github.houbb : heaven jar 0.1.22

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

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.0.1