Code Monkey home page Code Monkey logo

gsonapt's Introduction

GsonAPT

It is base in Gson lib and use Annotation Processor.If you can add the @JsonBean annotation to bean,the json parse will be faster;

it can also process the bean without @JsonBean,which will be processed by default Gson.In addition you can use GsonAPT.setGson()to change the default Gson in GsonAPT.

How to use

step 1

dependencies {

...
compile project(':gsonaptannotation')

apt project(':gsonaptcomplier')

}

step 2: add the annotation to bean

@JsonBean public class LittleBean { String littleBeanName;

public String getLittleBeanName() {
    return littleBeanName;
}

public void setLittleBeanName(String littleBeanName) {
    this.littleBeanName = littleBeanName;
}

public LittleBean() {
}

public LittleBean(String littleBeanName) {
    this.littleBeanName = littleBeanName;
}

}

step 3:compile

compile will generate the GsonAPT class

step 4:use GsonAPT to replace new Gson()

    TestBean testBean = new TestBean();
    String str = GsonAPT.toJson(testBean);
    testBean = GsonAPT.fromJson(str,TestBean.class);

    Map<Integer, OtherBean> map = new HashMap<>();
    map.put(9, new OtherBean(""));
    map.put(1, new OtherBean(null));
    String mapStr = GsonAPT.toJson(map);
    map = GsonAPT.fromJson(mapStr,new TypeToken<Map<Integer, OtherBean>>() {
    }.getType());

How fast

how much time to parse the small bean:

times Gson toJson GsonAPT toJson Gson fromJson GsonAPT fromJson
10 3 1 10 1
10000 738 363 883 756
100000 8361 4420 10616 9346

how much time to parse the big bean:

times Gson toJson GsonAPT toJson Gson fromJson GsonAPT fromJson
1 673 325 811 700
10 7748 3740 9506 8182
times Gson toJson Speed / GsonAPT toJson Speed
10000(small) 49%
100000(small) 52%
1(big) 48%
10(big) 48%
times Gson fromJson Speed / GsonAPT fromJson Speed
10000(small) 86%
100000(small) 88%
1(big) 86%
10(big) 86%

attention

  1. the field should was public , default or have the get/set method in the bean
  2. it no support the non-static inner class like the default Gson

gsonapt's People

Contributors

xuan835060947 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.