Simple JSON serialization and deserialization from/to object.
Yet another JSON object serializer/deserializer, that is small and relatively fast.
Simple array from JSON | Complex object from JSON | Simple array to JSON | Complex object to JSON | |
---|---|---|---|---|
Jackie | 3ms | 19ms | 2ms | 3ms |
Gson | 59ms | 66ms | 60ms | 60ms |
<dependency>
<groupId>cz.tvrzna</groupId>
<artifactId>jackie</artifactId>
<version>0.4.3</version>
</dependency>
Let have sample object class, that defines primitive structure.
JackieExample.java
package test.project;
import java.util.Date;
import cz.tvrzna.jackie.Jackie;
public class JackieExample
{
private Long id;
private String name;
private boolean active;
private Date createDate;
public JackieExample()
{
}
public JackieExample(Long id, String name, boolean active, Date createDate)
{
this.id = id;
this.name = name;
this.active = active;
this.createDate = createDate;
}
}
Jackie jackie = new Jackie();
JackieExample example = new JackieExample(123456789l, "Jackie's example", true, new Date());
System.out.println(jackie.toJson(example));
and the result is
{"id":123456789,"name":"Jackie's example","active":true,"createDate":"2020-03-10T13:43:24"}
final String json = "[{\"id\":123456789,\"name\":\"Jackie's example\",\"active\":true,\"createDate\":\"2020-03-10T13:43:24\"}]";
Jackie jackie = new Jackie();
JackieExample example = jackie.fromJson(json, JackieExample.class);
final String json = "[{\"id\":123456789,\"name\":\"Jackie's example\",\"active\":true,\"createDate\":\"2020-03-10T13:43:24\"}]";
Jackie jackie = new Jackie();
List<JackieExample> lstExamples = jackie.fromJson(json, List.class, JackieExample.class);
final String json = "{0: {\"id\":123456789,\"name\":\"Jackie's example\",\"active\":true,\"createDate\":\"2020-03-10T13:43:24\"}}";
Jackie jackie = new Jackie();
Map<Integer, JackieExample> mapExample = jackie.fromJson(json, Map.class, Integer.class, JackieExample.class);