Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fd9569

Browse files
committed
add fallbacks for poll fields
1 parent 75ccbbe commit 9fd9569

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/de/taimos/gpsd4java/backend/ResultParser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* #L%
2121
*/
2222

23+
import java.util.Collections;
24+
2325
import org.json.JSONObject;
2426

2527
import de.taimos.gpsd4java.types.ATTObject;
@@ -260,6 +262,9 @@ protected IGPSObject parsePOLL(final JSONObject json) throws ParseException {
260262
poll.setTimestamp(this.parseTimestamp(json, "time"));
261263
} else if (json.has("timestamp")) {
262264
poll.setTimestamp(json.optDouble("timestamp", Double.NaN));
265+
} else {
266+
// fallback to current timestamp
267+
poll.setTimestamp(System.currentTimeMillis());
263268
}
264269

265270
poll.setActive(json.optInt("active", 0));
@@ -268,16 +273,22 @@ protected IGPSObject parsePOLL(final JSONObject json) throws ParseException {
268273
poll.setFixes(this.parseObjectArray(json.optJSONArray("tpv"), TPVObject.class));
269274
} else if (json.has("fixes")) {
270275
poll.setFixes(this.parseObjectArray(json.optJSONArray("fixes"), TPVObject.class));
276+
} else {
277+
poll.setFixes(Collections.<TPVObject>emptyList());
271278
}
272279

273280
if (json.has("sky")) {
274281
poll.setSkyviews(this.parseObjectArray(json.optJSONArray("sky"), SKYObject.class));
275282
} else if (json.has("skyviews")) {
276283
poll.setSkyviews(this.parseObjectArray(json.optJSONArray("skyviews"), SKYObject.class));
284+
} else {
285+
poll.setSkyviews(Collections.<SKYObject>emptyList());
277286
}
278287

279288
if (json.has("gst")) {
280289
poll.setGst(this.parseObjectArray(json.optJSONArray("gst"), GSTObject.class));
290+
} else {
291+
poll.setGst(Collections.<GSTObject>emptyList());
281292
}
282293
gps = poll;
283294
return gps;

0 commit comments

Comments
 (0)