Skip to content

Repository files navigation

AndroidJsonModel

Json model 转换,支持修改父类json变量的key值

Import

JitPack

Add it in your project's build.gradle at the end of repositories:

repositories {
// ...
maven { url "https://jitpack.io" }
}

Step 2. Add the dependency in the form

dependencies {
compile 'com.github.vilyever:AndroidJsonModel:1.2.0'
}

Usage

voidmain() {
// create a sample model to generate json stringAppleapple = newApple();
apple.name = "apple";
apple.color = "red";
// get sample json stringStringjsonString = apple.toJson().toString();
// generate model from json stringapple = newJson<>(Apple.class).modelFromJsonString(jsonString);
}
publicstaticclassFruitextendsJsonModel {
@JsonKey("nam")
publicStringname;
}
publicstaticclassAppleextendsFruit {
@JsonKey("col")
publicStringcolor;
@OverridepublicHashMap<String, String> getJsonKeyBindingDictionary() {
HashMapdictionary = super.getJsonKeyBindingDictionary();
// change the super json key// left is the var name, right is the json key// 建议使用 AndroidKeyPath 中的方法输入变量名,避免输入的变量名拼写错误dictionary.put("name", "aname");
returndictionary;
}
}

License

Apache License Version 2.0

About

Json model 转换

Resources

Stars

8 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages