Skip to content

Commit eff7671

Browse files
author
Noor Dawod
committed
Fixed a small bug when a value is null.
1 parent 7e5d89a commit eff7671

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,50 +170,50 @@ public void writeTo(final OutputStream out) throws IOException {
170170
// Evaluate the value (which cannot be null).
171171
Object value = jsonParams.get(key);
172172

173-
// Bail out prematurely if value's null.
174-
if (value == null) {
175-
continue;
176-
}
177-
178173
// Write the JSON object's key.
179174
os.write(escape(key));
180175
os.write(':');
181176

182-
// Check if this is a FileWrapper.
183-
isFileWrapper = value instanceof RequestParams.FileWrapper;
184-
185-
// If a file should be uploaded.
186-
if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
187-
// All uploads are sent as an object containing the file's details.
188-
os.write('{');
177+
// Bail out prematurely if value's null.
178+
if (value == null) {
179+
os.write(JSON_NULL);
180+
} else {
181+
// Check if this is a FileWrapper.
182+
isFileWrapper = value instanceof RequestParams.FileWrapper;
183+
184+
// If a file should be uploaded.
185+
if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
186+
// All uploads are sent as an object containing the file's details.
187+
os.write('{');
188+
189+
// Determine how to handle this entry.
190+
if (isFileWrapper) {
191+
writeToFromFile(os, (RequestParams.FileWrapper) value);
192+
} else {
193+
writeToFromStream(os, (RequestParams.StreamWrapper) value);
194+
}
189195

190-
// Determine how to handle this entry.
191-
if (isFileWrapper) {
192-
writeToFromFile(os, (RequestParams.FileWrapper) value);
196+
// End the file's object and prepare for next one.
197+
os.write('}');
198+
} else if (value instanceof JsonValueInterface) {
199+
os.write(((JsonValueInterface) value).getEscapedJsonValue());
200+
} else if (value instanceof org.json.JSONObject) {
201+
os.write(((org.json.JSONObject) value).toString().getBytes());
202+
} else if (value instanceof org.json.JSONArray) {
203+
os.write(((org.json.JSONArray) value).toString().getBytes());
204+
} else if (value instanceof Boolean) {
205+
os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
206+
} else if (value instanceof Long) {
207+
os.write((((Number) value).longValue() + "").getBytes());
208+
} else if (value instanceof Double) {
209+
os.write((((Number) value).doubleValue() + "").getBytes());
210+
} else if (value instanceof Float) {
211+
os.write((((Number) value).floatValue() + "").getBytes());
212+
} else if (value instanceof Integer) {
213+
os.write((((Number) value).intValue() + "").getBytes());
193214
} else {
194-
writeToFromStream(os, (RequestParams.StreamWrapper) value);
215+
os.write(escape(value.toString()));
195216
}
196-
197-
// End the file's object and prepare for next one.
198-
os.write('}');
199-
} else if (value instanceof JsonValueInterface) {
200-
os.write(((JsonValueInterface) value).getEscapedJsonValue());
201-
} else if (value instanceof org.json.JSONObject) {
202-
os.write(((org.json.JSONObject) value).toString().getBytes());
203-
} else if (value instanceof org.json.JSONArray) {
204-
os.write(((org.json.JSONArray) value).toString().getBytes());
205-
} else if (value instanceof Boolean) {
206-
os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
207-
} else if (value instanceof Long) {
208-
os.write((((Number) value).longValue() + "").getBytes());
209-
} else if (value instanceof Double) {
210-
os.write((((Number) value).doubleValue() + "").getBytes());
211-
} else if (value instanceof Float) {
212-
os.write((((Number) value).floatValue() + "").getBytes());
213-
} else if (value instanceof Integer) {
214-
os.write((((Number) value).intValue() + "").getBytes());
215-
} else {
216-
os.write(escape(value.toString()));
217217
}
218218
} finally {
219219
// Separate each K:V with a comma, except the last one.

0 commit comments

Comments
 (0)