Skip to content

Commit feae14c

Browse files
committed
upgrade java-json-api to v2.0.0, add WritableJSONArray/Object.
1 parent 62aebaa commit feae14c

File tree

12 files changed

+95
-47
lines changed

12 files changed

+95
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ To install the library add:
1414
maven { url "https://jitpack.io" }
1515
}
1616
dependencies {
17-
compile 'com.github.webee:fastjson-json-api-android:v1.4.0'
17+
compile 'com.github.webee:fastjson-json-api-android:v2.0.0'
1818
}
1919
```

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
2424
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
2727
compile 'com.android.support:appcompat-v7:24.2.1'
2828
testCompile 'junit:junit:4.12'
29+
compile project(':fastjson-json-api-android')
2930
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.github.webee.fastjson">
3+
package="com.github.webee.fastjson.test">
44

55
<application
66
android:allowBackup="true"

app/src/main/java/com/github/webee/fastjson/MainActivity.java renamed to app/src/main/java/com/github/webee/fastjson/test/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package com.github.webee.fastjson;
1+
package com.github.webee.fastjson.test;
22

3-
import android.support.v7.app.AppCompatActivity;
43
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
6+
import com.github.webee.fastjson.R;
57

68
public class MainActivity extends AppCompatActivity {
79

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
android:paddingLeft="@dimen/activity_horizontal_margin"
99
android:paddingRight="@dimen/activity_horizontal_margin"
1010
android:paddingTop="@dimen/activity_vertical_margin"
11-
tools:context="com.github.webee.fastjson.MainActivity">
11+
tools:context="com.github.webee.fastjson.test.MainActivity">
1212

1313
<TextView
1414
android:layout_width="wrap_content"

fastjson-json-api-android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
})
3333
compile 'com.android.support:appcompat-v7:24.2.1'
3434
compile 'com.alibaba:fastjson:1.1.55.android'
35-
compile 'com.github.webee:java-json-api:v1.4.0'
35+
compile 'com.github.webee:java-json-api:v2.0.0'
3636
testCompile 'junit:junit:4.12'
3737
}
3838

fastjson-json-api-android/src/main/java/com/github/webee/fastjson/JSONArray.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,6 @@ public com.github.webee.json.JSONObject getObject(int index) {
9090
return new JSONObject(jsonArray.getJSONObject(index));
9191
}
9292

93-
@Override
94-
public boolean push(Object value) {
95-
return jsonArray.add(Utils.resolveValue(value));
96-
}
97-
98-
@Override
99-
public Object set(int index, Object value) {
100-
return jsonArray.set(index, Utils.resolveValue(value));
101-
}
102-
103-
@Override
104-
public Object remove(int index) {
105-
return jsonArray.remove(index);
106-
}
107-
10893
@Override
10994
public String toJSONString() {
11095
return jsonArray.toJSONString();

fastjson-json-api-android/src/main/java/com/github/webee/fastjson/JSONObject.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ public JSONObject(com.alibaba.fastjson.JSONObject jsonObject) {
1919
this.jsonObject = jsonObject;
2020
}
2121

22+
@Override
2223
public Set<String> keySet() {
2324
return jsonObject.keySet();
2425
}
2526

27+
@Override
2628
public boolean hasKey(String key) {
2729
return jsonObject.containsKey(key);
2830
}
2931

32+
@Override
3033
public JSONType getType(String key) {
3134
return Commons.getType(jsonObject.get(key));
3235
}
3336

37+
@Override
3438
public boolean isNull(String key) {
3539
return jsonObject.get(key) == null;
3640
}
@@ -74,26 +78,21 @@ public Double getDouble(String key) {
7478
return jsonObject.getDouble(key);
7579
}
7680

81+
@Override
7782
public String getString(String key) {
7883
return jsonObject.getString(key);
7984
}
8085

86+
@Override
8187
public com.github.webee.json.JSONArray getArray(String key) {
8288
return new JSONArray(jsonObject.getJSONArray(key));
8389
}
8490

91+
@Override
8592
public com.github.webee.json.JSONObject getObject(String key) {
8693
return new JSONObject(jsonObject.getJSONObject(key));
8794
}
8895

89-
public Object set(String key, Object value) {
90-
return jsonObject.put(key, Utils.resolveValue(value));
91-
}
92-
93-
public Object remove(String key) {
94-
return jsonObject.remove(key);
95-
}
96-
9796
@Override
9897
public String toJSONString() {
9998
return jsonObject.toJSONString();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.webee.fastjson;
2+
3+
import com.github.webee.json.Utils;
4+
5+
/**
6+
* Created by webee on 16/12/16.
7+
*/
8+
9+
public class WritableJSONArray extends JSONArray implements com.github.webee.json.WritableJSONArray {
10+
public WritableJSONArray(com.alibaba.fastjson.JSONArray jsonArray) {
11+
super(jsonArray);
12+
}
13+
14+
@Override
15+
public boolean push(Object value) {
16+
return jsonArray.add(Utils.resolveValue(value));
17+
}
18+
19+
@Override
20+
public Object set(int index, Object value) {
21+
return jsonArray.set(index, Utils.resolveValue(value));
22+
}
23+
24+
@Override
25+
public Object remove(int index) {
26+
return jsonArray.remove(index);
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.webee.fastjson;
2+
3+
import com.github.webee.json.Utils;
4+
5+
/**
6+
* Created by webee on 16/12/16.
7+
*/
8+
9+
public class WritableJSONObject extends JSONObject implements com.github.webee.json.WritableJSONObject {
10+
public WritableJSONObject(com.alibaba.fastjson.JSONObject jsonObject) {
11+
super(jsonObject);
12+
}
13+
14+
@Override
15+
public Object set(String key, Object value) {
16+
return jsonObject.put(key, Utils.resolveValue(value));
17+
}
18+
19+
@Override
20+
public Object remove(String key) {
21+
return jsonObject.remove(key);
22+
}
23+
}

0 commit comments

Comments
 (0)