Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 1720667

Browse files
committed
Make JSON value readers always return null when key is not found.
(cherry picked from commit 269c08b)
1 parent 80eb2dc commit 1720667

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/main/java/synapticloop/b2/response/BaseB2Response.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ protected String readString(JSONObject response, String key) {
100100
*
101101
* @param key the key to read as an int and remove
102102
*
103-
* @return the read key (or -1 if it doesn't exist)
103+
* @return the read key (or null if it doesn't exist)
104104
*/
105-
protected int readInt(String key) {
105+
protected Integer readInt(String key) {
106106
final Object value = response.remove(key);
107107
if (null == value || JSONObject.NULL == value) {
108108
getLogger().warn("No field for key {}", key);
109-
return -1;
109+
return null;
110110
}
111111
return value instanceof Number ? ((Number) value).intValue() : Integer.parseInt(value.toString());
112112
}
@@ -116,13 +116,13 @@ protected int readInt(String key) {
116116
*
117117
* @param key the key to read as a long and remove
118118
*
119-
* @return the read key (or -1L if it doesn't exist)
119+
* @return the read key (or null if it doesn't exist)
120120
*/
121-
protected long readLong(String key) {
121+
protected Long readLong(String key) {
122122
final Object value = response.remove(key);
123123
if (null == value || JSONObject.NULL == value) {
124124
getLogger().warn("No field for key {}", key);
125-
return -1L;
125+
return null;
126126
}
127127
return value instanceof Number ? ((Number) value).longValue() : Long.parseLong(value.toString());
128128
}

0 commit comments

Comments
 (0)