A comparative analysis of jackson, fastjson and Gson

Fast is not the only factor to be considered. Compared with database IO, json parsing time is negligible.
2 fastjson has made many optimizations for specific requirements, resulting in less stringent checks, such as array [daylight saving time], summer time, or not at the end.
3. Jackson is more powerful and more configurable (fastjson)
For example, serialize guava types, serialize time and date in Java 8, and so on. Common configurations are as follows

    //When serializing BigDecimal, the original number is output or the scientific count is output. The default is false, that is, whether to Plain String () scientific count is output or not.
    //Allow JSON empty strings to be coerced into null object values

    //Allow single values to be processed as arrays

    //No duplicate keys, throw exceptions
    //Disallow using order() of int for Enum to deserialize Enum and throw exceptions
    //Do not report errors when there are attributes that cannot be mapped
    //Use null to indicate that a collection type field is not throwing an exception
    //Object is space-time and no exception is thrown

    //Allow the use of c/c++ style annotations in JSON
    //Mandatory escape of non-ascii characters
    //Allow unknown fields
    //Allow unreferenced field names in JSON
    //Time format
    objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    //Identify single quotation marks
    //Recognition of Special Characters
    //Recognizing Java 8 time
    objectMapper.registerModule(new ParameterNamesModule());
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JavaTimeModule());
    //Classes that identify Guava packages
    objectMapper.registerModule(new GuavaModule());

Setting different name s

// without annotation, we'd get "theName", but we want "name":
   public String getTheName() { return _name; }

Ignore attributes

// means that if we see "foo" or "bar" in JSON, they will be quietly skipped
// regardless of whether POJO has such properties
@JsonIgnoreProperties({ "foo", "bar" })
public class MyBean
   // will not be written as JSON; nor assigned from JSON:
   public String internal;

4 fastjson has some controversial implementations and poor code quality. https://pic3.zhimg.com/80/v2-...
fastjson may have memory leaks below jdk1.7 because of the use of substring, while JDK1.6 substring has keneng with memory leaks

Reference resources: https://www.programcreek.com/...

//JDK 6
String(int offset, int count, char value[]) {
this.value = value;
this.offset = offset;
this.count = count;
public String substring(int beginIndex, int endIndex) {
//check boundary
return new String(offset + beginIndex, endIndex - beginIndex, value); 

//JDK 7
public String(char value[], int offset, int count) {
    //check boundary
    this.value = Arrays.copyOfRange(value, offset, offset + count);
public String substring(int beginIndex, int endIndex) {
    //check boundary
    int subLen = endIndex - beginIndex;
    return new String(value, beginIndex, subLen);

5 Gson can handle three-tier nesting of json
Gson can automatically handle the three-tier nesting of json, for example, but both jackson and fast JSON are troublesome to handle (but JSON does not recommend multi-tier nesting in fact)

class C {
  B b;

class B{
 List<A> a

Class A{


jackson's approach to two-tier nesting: rewriting deserialization

public class Order {

    public String name;
    public List<Item> items;

class ItemsJsonDeserializer extends JsonDeserializer<List<Item>> {

    public List<Item> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        InnerItems innerItems = jp.readValueAs(InnerItems.class);

        return innerItems.elements;

    private static class InnerItems {
        public List<Item> elements;

public class Order {
  public String name;
  @JsonDeserialize(using = ItemsJsonDeserializer.class)
  public List<Item> items;

6. Jackson has a broader community base

Keywords: Java JSON JDK Database

Added by Gargouil on Tue, 01 Oct 2019 01:32:59 +0300