在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Instagram/ig-json-parser开源软件地址:https://github.com/Instagram/ig-json-parser开源编程语言:Java 88.5%开源软件介绍:ig-json-parserFast JSON parser for java projects. Getting startedThe easiest way to get started is to look at maven-example. For more comprehensive examples, check out the unit tests or the demo. GradleFor Java projects, to use this library, add this to your build.gradle file: allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
...
dependencies {
implementation 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT' // the runtime
implementation 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT' // the annotation processor
} For Android projects using Android Studio 3.0+ or Gradle 4.0+, you can enable the annotation processor as following:
If you are using older gradle versions, you can use old
If you are using other build systems, please find instructions here Requirements for model classesThere should be a package-visible no-argument constructor for each of your model classes. The fields also need to be package-visible. Each class that needs a serializer/deserializer generated should be
annotated with The following is an example of a very simple model class: @JsonType
class Dessert {
@JsonField(fieldName="type")
String type;
@JsonField(fieldName="rating")
float rating;
} Serializer/deserializerCompiling your model classes with the annotations will automatically
generate the serializer and deserializer. They will be in a generated
class with the same name as your class, except with the suffix
Dessert parsed = Dessert__JsonHelper.parseFromJson(inputJsonString); To serialize a class, run: String serialized = Dessert__JsonHelper.serializeToJson(dessertObject); Supported data typesThe following scalar types are supported:
The following collection types are supported:
If a json field is another dictionary, it can be represented by another
model class. That model class must also have the ProguardAdd the following lines to your proguard-rules file:
Advanced featuresPostprocessingIf you need to process your JSON after a first pass, you can change your @JsonType
public class Example {
@JsonField(fieldName = "container")
Container mContainer;
@JsonType
public static class Container {
@JsonField(fieldName = "questionable_design_choice")
List<QuestionableDesignChoice> mQuestionableDesignChoice;
}
@JsonType(postprocessingEnabled = true)
public static class QuestionableDesignChoice {
@JsonField(fieldName = "property")
String mProperty;
QuestionableDesignChoice postprocess() {
// post-process things here...
return this;
}
}
} Customized parsing codeParsing the supported data types is straightforward. For enums or built-in Java classes, you will need to add customized parsing. Value extract formatters override how we extract the value from the @JsonField(
fieldName = "position",
valueExtractFormatter =
"com.instagram.common.json.android.JsonTypeHelper.deserializePointF(${parser_object})",
serializeCodeFormatter =
"com.instagram.common.json.android.JsonTypeHelper.serializePointF("
+ "${generator_object}, \"${json_fieldname}\", ${object_varname}.${field_varname})")
@Nullable
protected PointF mPosition; Optional serializer generationTo save generating serializer code if you only need deserialization, serializer generation can be disabled or enabled globally and per-class. The default is to generate serializers for all classes. To disable generation globally, pass
to the command-line arguments of javac. To override the default generation option for a single class, see
ContributingSee the CONTRIBUTING file for how to help out. Licenseig-json-parser is MIT licensed, as found in the LICENSE file. Privacy Policy and Terms of Use |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论