Coder Social home page Coder Social logo

976112643 / safegson Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yanglang116/ikgson

14.0 2.0 1.0 4.59 MB

基于Gson的解析库,对基本类型进行容错处理(不会因为个别字段类型错误,导致整个Json解析失败)

License: Apache License 2.0

Java 100.00%

safegson's Introduction

Gson容错扩展库

改造后的Gson库,对常用的数据类型进行容错处理(若某一个字段由于数据类型不匹配,采用默认值处理)

  • 集成方式
  1. 添加jitpack仓库
	allprojects {
		repositories {
			...
			maven { url 'https://www.jitpack.io' }
		}
	}
  1. 加入依赖
	dependencies {
	        compile 'com.github.976112643:SafeGson:1.0'
	}
  • 容错模式默认开启,若需要修改,可以使用如下方法配置:
    GsonStrictMode.getInstance()
                 .setCheckTypeException(false)//是否检查类型异常,默认为false
                 .setBooleanVal(true)//设置各类型的默认值, 调用后默认不再检查类型
                 .setIntVal(-110)
                 .setStringVal("类型错啦,")
                 .setNullArray(true)//数组类型是否为null
                 .setNullObject(false);//对象类型是否为null

2. 容错模式下常用类型采用的默认值

类型 默认值
byte 0
short 0
int 0
long 0L
float 0.0F
double 0.0D
chat '\0'
String ""
Boolean false
Array(数组) [] 空数组
List(集合) [] 空集合
Objec(对象) null

Thanks to the open source project

safegson's People

Contributors

976112643 avatar amogilev avatar anirudhramanan avatar arouel avatar baschdl avatar cconroy avatar chaitanyapramod avatar deyboy90 avatar dongjoon-hyun avatar dorvaryn avatar egor-n avatar guptasourabh04 avatar heidid avatar igormiller avatar imysak avatar inder123 avatar jakewharton avatar joaaoverona avatar joel-leitch avatar juandiana avatar lyubomyr-shaydariv avatar mbrukman avatar melquiadess avatar nightlynexus avatar paniko0 avatar qwwdfsad avatar sgbrown avatar swankjesse avatar yanglang116 avatar yasirmhd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wangyutao3

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.