Coder Social home page Coder Social logo

jsntmf / jsonlube Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alibaba/jsonlube

0.0 2.0 0.0 5.32 MB

为了高效地将Json对象转化成Java bean对象,传统上我们是在运行是利用反射来实现。但是在移动平台上,面对复杂的Json,采用反射的方式往往性能比较差,为了追求极致的性能,我们可以采用Android原生的Json库进行解析。但是面对一个复杂的大Json,基于原生Json库去手动解析工作量太大,且容易出错。JsonLube是为此而设计的。JsonLube会在编译期自动生成Json解析代码,用户使用方式简单,但是却能收获原生解析的性能。

Java 100.00%

jsonlube's Introduction

JsonLube

功能简述

JsonLube用于将Json对象转成JAVA Bean对象,不同于传统在运行时进行反射的方式,JsonLube采用在编译时自动生成解析Json的代码,使用方式依然简单,然而在移动平台上却可以收获更好的性能。

使用方式

gradle配置

    annotationProcessor 'com.alibaba.android:jsonlube-compiler:1.0.0.0@jar'
    compile ('com.alibaba.android:jsonlube:1.0.0.3@aar'){
        transitive=true
    }

Proguard配置

-keep @com.alibaba.android.jsonlube.ProguardKeep public class *

Json -> Java Bean

//1. 在代码中直接调用 JsonLube.fromJson()将Json对象转成Java bean对象。
Teacher teacherBean = JsonLube.fromJson(jsonData, Teacher.class);

//2. 在Teacher类的定义中加上@ToJson注解
@FromJson
public class Teacher {
	...
}

Java Bean -> Json

//1. 直接调用JsonLube.toJson()函数
JsonObject teacherJson = JsonLube.toJson(teacherBean);

//2. 在Teacher类的定义中加上@ToJson注解
@ToJson
public class Teacher {
	···
}

具体的bean的例子

//在JsonLube.fromJson()/JsonLube.toJson()直接使用到的Java bean类需要加上@FromJson/@ToJson注解,间接引用到的bean无需添加。
//这两个注解根据需要自行添加,如果只需要做反序列化能力,则添加@FromJson一个就够了。
@FromJson
@ToJson
public class Teacher {
	public String name; //支持public成员变量

	private int age; // 支持getter / setter函数

	public int getAge(){
		return this.age;
	}

	public void setAge(int age){
		this.age = age;
	}

	@JsonLubeField(name="sex")
	public int s;


	public List<Student> students;  //支持bean的嵌套
}


public class Student {
	public String name;
	public int age;
	public int sex;
}

jsonlube's People

Contributors

zhangsl avatar

Watchers

James Cloos avatar  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.