Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #41 from vimeo/dev
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
anthonycr authored Jan 26, 2017
2 parents b635667 + debc449 commit 0eeb27b
Show file tree
Hide file tree
Showing 86 changed files with 3,952 additions and 1,241 deletions.
30 changes: 30 additions & 0 deletions .travis.yml
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=
5 changes: 5 additions & 0 deletions Dangerfile
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
2 changes: 2 additions & 0 deletions Gemfile
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)
68 changes: 67 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,46 @@ GEM
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
babosa (1.0.2)
backports (3.6.8)
claide (1.0.1)
claide-plugins (0.9.2)
cork
nap
open4 (~> 1.3)
colored (1.2)
colorize (0.8.1)
commander (4.4.1)
highline (~> 1.7.2)
connection_pool (2.2.1)
cork (0.2.0)
colored (~> 1.2)
danger (4.0.5)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored (~> 1.2)
cork (~> 0.1)
faraday (~> 0.9)
faraday-http-cache (~> 1.0)
git (~> 1)
kramdown (~> 1.5)
octokit (~> 4.2)
terminal-table (~> 1)
danger-junit (0.7.2)
danger (> 2.0)
ox (~> 2.0)
domain_name (0.5.20161129)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.1)
ethon (0.10.1)
ffi (>= 1.3.0)
excon (0.54.0)
faraday (0.10.0)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday-http-cache (1.3.1)
faraday (~> 0.8)
faraday_middleware (0.10.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.0.1)
Expand Down Expand Up @@ -64,7 +90,16 @@ GEM
colorize
nokogiri
terminal-table
ffi (1.9.17)
gh (0.14.0)
addressable
backports
faraday (~> 0.8)
multi_json (~> 1.0)
net-http-persistent (>= 2.7)
net-http-pipeline
gh_inspector (1.0.2)
git (1.3.0)
google-api-client (0.9.20)
addressable (~> 2.3)
googleauth (~> 0.5)
Expand All @@ -90,6 +125,9 @@ GEM
i18n (0.7.0)
json (1.8.3)
jwt (1.5.6)
kramdown (1.13.2)
launchy (2.4.3)
addressable (~> 2.3)
little-plugger (1.1.4)
logging (2.1.0)
little-plugger (~> 1.1)
Expand All @@ -105,16 +143,30 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.3)
nap (1.1.0)
net-http-persistent (3.0.0)
connection_pool (~> 2.2)
net-http-pipeline (1.0.1)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
octokit (4.6.2)
sawyer (~> 0.8.0, >= 0.5.3)
open4 (1.3.4)
os (0.9.6)
ox (2.4.8)
plist (3.2.0)
public_suffix (2.0.4)
pusher-client (0.6.2)
json
websocket (~> 1.0)
representable (2.3.0)
uber (~> 0.0.7)
retriable (2.1.0)
rouge (1.11.1)
rubyzip (1.2.0)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
security (0.1.3)
signet (0.7.3)
addressable (~> 2.3)
Expand All @@ -126,13 +178,25 @@ GEM
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
thread_safe (0.3.5)
travis (1.8.5)
backports
faraday (~> 0.9)
faraday_middleware (~> 0.9, >= 0.9.1)
gh (~> 0.13)
highline (~> 1.6)
launchy (~> 2.1)
pusher-client (~> 0.4)
typhoeus (~> 0.6, >= 0.6.8)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uber (0.0.15)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode-display_width (1.1.2)
websocket (1.2.3)
word_wrap (1.0.0)
xcodeproj (1.4.2)
CFPropertyList (~> 2.3.3)
Expand All @@ -149,8 +213,10 @@ PLATFORMS
ruby

DEPENDENCIES
danger-junit (= 0.7.2)
fastlane (= 2.1.1)
fastlane-plugin-pretty_junit
travis (= 1.8.5)

BUNDLED WITH
1.13.6
1.13.7
100 changes: 63 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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'
}
```

Expand Down Expand Up @@ -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 {
Expand All @@ -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"
}

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ allprojects {

subprojects {
group = 'com.vimeo.stag'
version = '1.2.1'
version = '2.0.0'
}
10 changes: 0 additions & 10 deletions circle.yml

This file was deleted.

Loading

0 comments on commit 0eeb27b

Please sign in to comment.