Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Commit 78ddb53

Browse files
authored
Merge pull request #26 from mikepschneider/master
Meta object reader
2 parents 60faed5 + 5b77551 commit 78ddb53

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

JsonAPI/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
ext {
44
PUBLISH_GROUP_ID = 'com.gustavofao'
55
PUBLISH_ARTIFACT_ID = 'JSONApi'
6-
PUBLISH_VERSION = '1.0.9.3'
6+
PUBLISH_VERSION = '1.0.9.4'
77
}
88

99
android {
@@ -14,7 +14,7 @@ android {
1414
minSdkVersion 9
1515
targetSdkVersion 23
1616
versionCode 8
17-
versionName "1.0.9.3"
17+
versionName "1.0.9.4"
1818
}
1919
buildTypes {
2020
release {
@@ -33,4 +33,4 @@ dependencies {
3333

3434
// ./gradlew clean build generateRelease
3535
// gradlew.bat clean build generateRelease
36-
apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
36+
apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'

JsonAPI/src/main/java/com/gustavofao/jsonapi/JSONApiConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.json.JSONException;
1919
import org.json.JSONObject;
2020

21-
import java.lang.annotation.Annotation;
2221
import java.lang.reflect.Field;
2322
import java.text.ParseException;
2423
import java.text.SimpleDateFormat;
@@ -141,6 +140,9 @@ public JSONApiObject fromJson(String jsonObject) {
141140
if (!json.isNull("links"))
142141
jsonApiObject.setLinks(linksFromJson(json.getJSONObject("links")));
143142

143+
if (!json.isNull("meta"))
144+
jsonApiObject.setMeta(json.getJSONObject("meta"));
145+
144146
Field hasErrors = jsonApiObject.getClass().getDeclaredField("hasErrors");
145147
boolean oldAcessible = hasErrors.isAccessible();
146148
hasErrors.setAccessible(true);

JsonAPI/src/main/java/com/gustavofao/jsonapi/Models/JSONApiObject.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.gustavofao.jsonapi.Models;
22

3+
import org.json.JSONObject;
4+
35
import java.util.ArrayList;
46
import java.util.List;
57

@@ -9,6 +11,7 @@ public class JSONApiObject {
911
private Links links;
1012
private boolean hasErrors = true;
1113
private List<ErrorModel> errors;
14+
private JSONObject meta;
1215

1316
public JSONApiObject() {
1417
data = new ArrayList<>();
@@ -45,4 +48,13 @@ public boolean hasErrors() {
4548
public List<ErrorModel> getErrors() {
4649
return errors;
4750
}
51+
52+
public JSONObject getMeta() {
53+
return meta;
54+
}
55+
56+
public void setMeta(JSONObject meta) {
57+
this.meta = meta;
58+
}
59+
4860
}

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A simple way to implement JSONApi specifications to convert Models to Json and J
77
Add this dependecy from jCenter:
88

99
```gradle
10-
compile 'com.gustavofao:JSONApi:1.0.9.3@aar'
10+
compile 'com.gustavofao:JSONApi:1.0.9.4@aar'
1111
```
1212

1313
If the installation fails, add this line to your gradle top level:
@@ -39,7 +39,7 @@ public class Comment extends Resource {
3939

4040
private String body;
4141
private Person author;
42-
42+
4343
/*
4444
Important: If you leave this out, de-serialisation might fail "... has no zero argument constructor"
4545
*/
@@ -178,6 +178,14 @@ When you have different types for the same object you can use the annotation @Ty
178178
@Types({"test", "test02"})
179179
```
180180

181+
#### METADATA
182+
Meta data can be retrieved from the JSONApiObject using getMeta()
183+
184+
```java
185+
JSONApiObject obj = api.fromJson(json);
186+
JSONObject meta = obj.getMeta();
187+
```
188+
181189
## ERRORS
182190
The documentation from errors can be found in [this link](http://jsonapi.org/examples/#error-objects-multiple-errors).
183191
To handle with it you have to check your **JSONApiObject** if it *hasErrors()*.
@@ -192,7 +200,7 @@ if (obj.hasErrors()) {
192200
}
193201
```
194202

195-
The attributes from ErrorModel are:
203+
The attributes from ErrorModel are:
196204
```java
197205
private String status;
198206
private String title;
@@ -262,7 +270,7 @@ At this moment we can do the mapping listed above (java -> Json):
262270
* float -> Double
263271
* int -> Integer
264272
* boolean -> Boolean
265-
* Map -> JSONObject
273+
* Map -> JSONObject
266274
* Resouce -> Relationship + Include
267275

268276
## Thanks

0 commit comments

Comments
 (0)