This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from vimeo/dev
v2.0.0
- Loading branch information
Showing
86 changed files
with
3,952 additions
and
1,241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
language: android | ||
jdk: | ||
- oraclejdk8 | ||
android: | ||
components: | ||
- tools | ||
- build-tools-25.0.2 | ||
- android-25 | ||
- extra-android-support | ||
- extra-android-m2repository | ||
before_cache: | ||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock | ||
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/ | ||
cache: | ||
directories: | ||
- "$HOME/.gradle/caches/" | ||
- "$HOME/.gradle/wrapper/" | ||
- "$HOME/.android/build-cache" | ||
script: | ||
- rvm install 2.2 | ||
- rvm use 2.2 | ||
- bundle install | ||
- FASTLANE_SKIP_UPDATE_CHECK=1 bundle exec fastlane test | ||
|
||
# https://vimeo.slack.com/services/B3TG0UCR3 | ||
# travis encrypt "<acct>:<token>#<channel>" --add notifications.slack.rooms | ||
notifications: | ||
slack: | ||
rooms: | ||
secure: psEjUOvylqjlGlH2p6SQUkAZdFR//+JB/Z98Uqg7N5qb/ZwYepFwMtzXuZpDcv1wFI8Znh0m5n3zAmBpYgG27gmS8BZZg/U9GmSN8HmaR3IGa9Qp7VKbrBet6GhMjVRzCi+kXYgq8rSw4/yhx/LpfgCeZRqcECbf3HJJlnSPBivIjSMM/+BjUEQb5smHDRYPHHXxl2lHMJcK9h2T/9ie/xoUbKZLokITHXXyvNtUNbA27NE3aWh0cUXj2DxhYWrlmQWgQq4wjUqn27WW/MthfBn6+nGAiQYQ3SdUIh5LJIQY6XE+5LfWJvZHa7Rt6DmiiGDJjYOa4LUYTds8FDCCfjLOIqmUvwHaGMzDZrhsdN2/eJ6CZWWwn1aPE/V+YN1bk8UTgHIu9RCBOv9SepG9CZmtecNXU8MTYUqvPvjM3F2OrDM04COLJiqSch78+LVC/BsZyaQfzP6dLZCffjMP49rDsqrqgZZsaNqSlApNkiX0y9OiujpDedVJ1gp49jnkoxbU9GWYWOyHQpJ/++84D61tNhnrCoNArl3KraWKtQdyKXnMUfAkTQ/9mohsJMGhc2RqWSGcAHmK+Z/3SIIV2VBFqX45NO2StVFSql4aDQPQDoo5T1nPVCHdnMUcoitZDjFgflGvxqCu7qIq364p7YBOa5pH+BzaGywkkRRpYcM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Print reports for each test result | ||
Dir.glob('stag-library*build/test-results/*.xml') do |result| | ||
junit.parse result | ||
junit.report | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
source 'https://rubygems.org' | ||
gem 'fastlane', '2.1.1' | ||
gem 'danger-junit', '0.7.2' | ||
gem 'travis', '1.8.5' | ||
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') | ||
eval(File.read(plugins_path), binding) if File.exist?(plugins_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ Stag improves Gson performance by automatically generating reflection-less TypeA | |
|
||
| Branch | Build Status | | ||
|--------|--------------| | ||
| master | [![Build Status](https://circleci.com/gh/vimeo/stag-java/tree/master.svg?style=shield&circle-token=4d5dd11678a93587658d1677d0ef2b8c64b56574)](https://circleci.com/gh/vimeo/stag-java/tree/master) | | ||
| dev | [![Build Status](https://circleci.com/gh/vimeo/stag-java/tree/dev.svg?style=shield&circle-token=4d5dd11678a93587658d1677d0ef2b8c64b56574)](https://circleci.com/gh/vimeo/stag-java/tree/dev) | | ||
| master | [![Build Status](https://travis-ci.org/vimeo/stag-java.svg?branch=master)](https://travis-ci.org/vimeo/stag-java) | | ||
| dev | [![Build Status](https://travis-ci.org/vimeo/stag-java.svg?branch=dev)](https://travis-ci.org/vimeo/stag-java) | | ||
|
||
|
||
## Why Build Stag? | ||
|
@@ -25,8 +25,8 @@ The Stag library solves this problem. It leverages annotations to automatically | |
from jCenter | ||
```groovy | ||
dependencies { | ||
compile 'com.vimeo.stag:stag-library:1.2.1' | ||
apt 'com.vimeo.stag:stag-library-compiler:1.2.1' | ||
compile 'com.vimeo.stag:stag-library:2.0.0' | ||
apt 'com.vimeo.stag:stag-library-compiler:2.0.0' | ||
} | ||
``` | ||
|
||
|
@@ -70,7 +70,7 @@ buildscript { | |
apply plugin: 'com.neenbedankt.android-apt' | ||
``` | ||
|
||
#### 3. Passing package name as an argument for the generated files (Optional) | ||
#### 3. Pass package name as an argument for the generated files (Optional) | ||
By default, the files will be in generated in `com.vimeo.sample.stag.generated` package. But, you can specify your own package for the generated files by passing it as an argument to the apt compiler. | ||
```groovy | ||
apt { | ||
|
@@ -80,61 +80,75 @@ apt { | |
} | ||
``` | ||
|
||
## Stag Rules | ||
## Features | ||
|
||
1. Make sure the member variables of your model class are not private (i.e. public, protected, or package-local visibility) | ||
2. Make sure your model class is not private and has a zero argument non-private constructor | ||
3. Annotate each member variable you want populated | ||
- `@GsonAdapterKey("json_key")`: populates the field using the JSON value with the specified key | ||
- `@GsonAdapterKey`: populates the field using the JSON value with the key named the same as the member variable | ||
- Use your favorite `@NonNull` annotation to tell Stag to throw an exception if the field is null while deserializing or while serializing the object. | ||
4. Register the `Stag.Factory` with Gson when you create your Gson instance: `Gson gson = new GsonBuilder().registerTypeAdapterFactory(new Stag.Factory()).create();` | ||
5. You're done! | ||
#### 1. Class Level Annotation | ||
|
||
Stag supports class level annotation `@UseStag` which processes all the fields for a particular class, which makes it easy to use and integrate. | ||
|
||
`@UseStag` has three different variants: | ||
|
||
- `@UseStag(FieldOption.ALL)` : Will serialize/de-serialize all member variables which are not static or transient | ||
- `@UseStag(FieldOption.NONE)` : Will skip serialization and deserialization for all member variables. Only member variables inherited from annotated classes will be included. | ||
- `@UseStag(FieldOption.SERIALIZED_NAME)` : Will Serialize or Deserialize Fields only which are annotated with `SerializedName` or `GsonAdapterKey` (deprecated). | ||
|
||
## Supported Types | ||
#### 2. `@SerializedName("key")` Support | ||
|
||
- YES: All native types supported by Gson (boolean, double, int, long, float) | ||
- YES: String types | ||
- YES: ArrayList or any other List interfaces are supported | ||
- YES: HashMaps or any other Map interfaces are supported | ||
- YES: Complex data structures supported | ||
- YES: Enumerations (enums) | ||
Similar to GSON, you can use the`@SerializedName` annotation to provide a different JSON name to a member field. It also supports alternate name feature of the `@SerializedName` annotation. | ||
`@SerializedName("name")` or `@SerializedName(value = "name", alternate = {"name1", "name2"})`. | ||
|
||
Note : | ||
- `@SerializedName("json_key")` annotations you might be using will be ignored. | ||
#### 3. Cross Module Support | ||
|
||
Stag has the ability to reference TypeAdapters across modules. | ||
|
||
#### 4. Parity with GSON | ||
|
||
Last but not the least, Stag is almost in parity with GSON. | ||
|
||
## Stag Rules | ||
|
||
1. Make sure the member variables of your model class are not private (should be public, protected, or package-local visibility) | ||
2. Make sure your model class is not private and has a zero argument non-private constructor | ||
3. Annotate the classes with `@UseStag` annotation. This will process all the member variables of the class, which makes it easy to use. | ||
4. Use the `@SerializedName("key")` annotation to give the variables a different JSON name. (same as GSON) | ||
5. Use your favorite `@NonNull` annotation to tell Stag to throw an exception if the field is null while deserializing or while serializing the object. | ||
6. Register the `Stag.Factory` with Gson when you create your Gson instance: `Gson gson = new GsonBuilder().registerTypeAdapterFactory(new Stag.Factory()).create();` | ||
7. You're done! | ||
|
||
<b>NOTE</b>: `@GsonAdapterKey` has been deprecated and will be removed in a future release. It is advisable to migrate to `@SerializedName` and `@UseStag` annotations. | ||
|
||
See the [example below](#example) or the [sample app](sample) to get more info on how to use Stag. | ||
|
||
## Example | ||
|
||
```java | ||
@UseStag | ||
public class Deer { | ||
@GsonAdapterKey("name") | ||
@SerializedName("name") | ||
String mName; // mName = json value with key "name" | ||
|
||
@GsonAdapterKey("species") | ||
@SerializedName("species") | ||
String mSpecies; // mSpecies = json value with key "species" | ||
|
||
@GsonAdapterKey("age") | ||
@SerializedName("age") | ||
int mAge; // mAge = json value with key "age" | ||
|
||
@GsonAdapterKey("points") | ||
@SerializedName("points") | ||
int mPoints; // mPoints = json value with key "points" | ||
|
||
@GsonAdapterKey("weight") | ||
float mWeight; // mWeight = json value with key "weight" | ||
@SerializedName("weight") | ||
float mWeight; // mWeight = json value with key "weight" | ||
} | ||
|
||
@UseStag | ||
public class Herd { | ||
|
||
@NonNull // add NonNull annotation to throw an exception if the field is null | ||
@GsonAdapterKey | ||
ArrayList<Deer> data_list; // data_list = json value with key "data_list" | ||
@NonNull // add NonNull annotation to throw an exception if the field is null | ||
@SerializedName("data_list") | ||
ArrayList<Deer> data; // data_list = json value with key "data_list" | ||
|
||
@GsonAdapterKey | ||
List<Deer> data_list_copy; // data_list_copy = json value with key "data_list_copy" | ||
List<Deer> data_list_copy; // data_list_copy = json value with key "data_list_copy" | ||
|
||
@GsonAdapterKey | ||
Map<String, Deer> data_map; // data_map = json value with key "data_map" | ||
} | ||
|
||
|
@@ -159,8 +173,20 @@ MyParsingClass { | |
## Future Enhancements | ||
|
||
- Add an option to absorb parsing errors rather than crashing and halting parsing (default gson behavior) | ||
- Class level annotation so that you don't have to annotate each field | ||
- Support using `@SerializedName` annotation | ||
|
||
## Development | ||
```sh | ||
git clone [email protected]:vimeo/stag-java.git | ||
cd stag-java | ||
bundle install | ||
# dev like a boss | ||
bundle exec fastlane test | ||
# commit and push like a boss | ||
``` | ||
|
||
#### Manage build dependencies | ||
Aside from specifying Java dependencies in the `.gradle` files, you can use the `.travis.yml` file to specify external build depencies such as the Android SDK to compile against (see the `android.components` section). | ||
|
||
|
||
## License | ||
`stag-java` is available under the MIT license. See the [LICENSE](LICENSE) file for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ allprojects { | |
|
||
subprojects { | ||
group = 'com.vimeo.stag' | ||
version = '1.2.1' | ||
version = '2.0.0' | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.