Skip to content

Commit 27f22c0

Browse files
author
Noor Dawod
committed
Introduce an interface for adding arbitrary JSON objects.
1 parent 4717ae8 commit 27f22c0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

library/src/main/java/com/loopj/android/http/JsonStreamerEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ public void writeTo(final OutputStream out) throws IOException {
190190

191191
// End the file's object and prepare for next one.
192192
os.write('}');
193+
} else if (value instanceof JsonValueInterface) {
194+
os.write(((JsonValueInterface) value).getEscapedJsonValue());
193195
} else if (value instanceof Boolean) {
194196
os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
195197
} else if (value instanceof Long) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Android Asynchronous Http Client
3+
Copyright (c) 2011 James Smith <[email protected]>
4+
http://loopj.com
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package com.loopj.android.http;
20+
21+
/**
22+
* This interface is used to encapsulate JSON values that are handled entirely
23+
* by the app. For example, apps could manage any type of JSON on their own (and
24+
* not rely on {@link org.json.JSONArray} or {@link org.json.JSONObject} to
25+
* exchange data.
26+
*
27+
* @author Noor Dawod <[email protected]>
28+
*/
29+
public interface JsonValueInterface {
30+
31+
/**
32+
* Returns the escaped, ready-to-be used value of this encapsulated object.
33+
*
34+
* @return byte array holding the data to be used (as-is) in a JSON object
35+
*/
36+
byte[] getEscapedJsonValue();
37+
}

0 commit comments

Comments
 (0)