List of usage examples for com.google.gson.stream JsonReader nextInt
public int nextInt() throws IOException
From source file:data.Task1bData.java
License:Apache License
private ArrayList<Snippet> readSnippets(JsonReader reader) { ArrayList<Snippet> snippets = new ArrayList<Snippet>(); try {//from ww w . j a v a 2s . com reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); String document = "", fnameBegin = "", fnameEnd = "", text = ""; int beginIndex = 0; int endIndex = 0; while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("offsetInBeginSection")) { beginIndex = reader.nextInt(); } else if (name.equals("offsetInEndSection")) { endIndex = reader.nextInt(); } else if (name.equals("document")) { document = reader.nextString(); } else if (name.equals("beginSection")) { fnameBegin = reader.nextString(); fnameBegin = fnameBegin.substring(fnameBegin.indexOf('.') + 1); } else if (name.equals("endSection")) { fnameEnd = reader.nextString(); fnameEnd = fnameEnd.substring(fnameEnd.indexOf('.') + 1); } else if (name.equals("text")) { text = reader.nextString(); } else { //System.out.println("Unknown field "+name +" in snippet"); } } Snippet sn = new Snippet(document, text, fnameBegin, fnameEnd, beginIndex, endIndex); reader.endObject(); snippets.add(sn); } reader.endArray(); } catch (IOException ex) { } return snippets; }
From source file:de.innovationgate.utils.GsonUtils.java
License:Open Source License
/** * Reads the next integer value from the reader or null if it is a null value * @param reader The reader//w w w. j av a 2 s .c o m * @return Integer value or null * @throws IOException */ public static Integer nextIntegerOrNull(JsonReader reader) throws IOException { if (reader.peek() != JsonToken.NULL) { return reader.nextInt(); } else { reader.nextNull(); return null; } }
From source file:edu.jhuapl.dorset.agents.ResponseCodeJsonAdapter.java
License:Open Source License
@Override public Code read(JsonReader reader) throws IOException { return Code.fromValue(reader.nextInt()); }
From source file:edu.rpi.shuttles.data.RPIShuttleDataProvider.java
License:Apache License
private Stop readStop(JsonReader reader) throws IOException { Stop stop = new Stop(); ArrayList<Integer> routes = new ArrayList<Integer>(); reader.beginObject();/* ww w. ja va2s .c om*/ reader.nextName(); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); if (key.equals("id")) { stop.id = reader.nextInt(); } else if (key.equals("name")) { stop.name = reader.nextString(); } else if (key.equals("short_name")) { stop.short_name = reader.nextString(); } else if (key.equals("enabled")) { stop.enabled = reader.nextBoolean(); } else if (key.equals("latitude")) { stop.latitude = reader.nextDouble(); } else if (key.equals("longitude")) { stop.longitude = reader.nextDouble(); } else if (key.equals("routes")) { reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { if (reader.nextName().equals("id")) { routes.add(reader.nextInt()); } else { reader.skipValue(); } } reader.endObject(); } reader.endArray(); } else { stop.extraAttributes.put(key, reader.nextString()); } } reader.endObject(); reader.endObject(); Log.d("RPIDataProvider", String.format("Pulling stop %S (%S)...", Integer.toString(stop.id), stop.name)); for (int i = 0; i < routes.size(); i++) { ArrayList<Integer> route = mRouteStopsMap.get(routes.get(i), new ArrayList<Integer>()); route.add(stop.id); mRouteStopsMap.put(routes.get(i), route); } return stop; }
From source file:edu.rpi.shuttles.data.RPIShuttleDataProvider.java
License:Apache License
private Route readRoute(JsonReader reader) throws IOException { Route route = new Route(); reader.beginObject();/*from w ww. j a va2 s . com*/ reader.nextName(); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); if (key.equals("id")) { route.id = reader.nextInt(); } else if (key.equals("name")) { route.name = reader.nextString(); } else if (key.equals("description")) { route.description = reader.nextString(); } else if (key.equals("enabled")) { route.enabled = reader.nextBoolean(); } else if (key.equals("color")) { route.map_color = reader.nextString(); } else { reader.skipValue(); } } reader.endObject(); reader.endObject(); Log.d("RouteDataProvider", String.format("Pulling route %S (%S)...", Integer.toString(route.id), route.name)); Log.d("RouteDataProvider", String.format("Route %S (%S) has %S stops.", Integer.toString(route.id), route.name, Integer.toString(mRouteStopsMap.get(route.id).size()))); return route; }
From source file:edu.rpi.shuttles.data.RPIShuttleDataProvider.java
License:Apache License
private void populateRoutePath(JsonReader reader) throws IOException { ArrayList<Coordinate> path = new ArrayList<Coordinate>(); Integer path_id = 0;//from w w w. j av a 2 s. c o m reader.beginObject(); while (reader.hasNext()) { // Process attributes of a route. // We have the array of coordinates making up the path of the route on a map. String key = reader.nextName(); if (key.equals("coords")) { Double latitude = 0.0; Double longitude = 0.0; reader.beginArray(); // Read coordinate attributes and add to path. while (reader.hasNext()) { reader.beginObject(); // Read coordinate attributes. while (reader.hasNext()) { String coordinate_key = reader.nextName(); if (coordinate_key.equals("latitude")) { latitude = reader.nextDouble(); } else if (coordinate_key.equals("longitude")) { longitude = reader.nextDouble(); } else { reader.skipValue(); } } reader.endObject(); // Add coordinate to path. path.add(new Coordinate(latitude, longitude)); Log.d("CreatePoint", String.format("Inserting point %S, %S", latitude.toString(), longitude.toString())); } reader.endArray(); } else if (key.equals("id")) { path_id = reader.nextInt(); } else { reader.skipValue(); } } reader.endObject(); Route route = mRoutes.get(path_id); route.map_polyline = path; mRoutes.put(path_id, route); Log.d("RouteDataProvider", String.format("Pulling route %S (%S) with %s coordinates...", Integer.toString(route.id), route.name, Integer.valueOf(route.map_polyline.size()).toString())); }
From source file:edu.rpi.shuttles.data.RPIShuttleDataProvider.java
License:Apache License
@SuppressLint("SimpleDateFormat") private Vehicle readVehicleLocation(JsonReader reader) throws IOException { Vehicle shuttle = new Vehicle(); reader.beginObject();/*from w ww. ja va 2 s . co m*/ reader.nextName(); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); if (key.equals("id")) { shuttle.id = reader.nextInt(); } else if (key.equals("name")) { shuttle.name = reader.nextString(); } else if (key.equals("latest_position")) { reader.beginObject(); while (reader.hasNext()) { key = reader.nextName(); if (key.equals("heading")) { shuttle.heading = reader.nextInt(); } else if (key.equals("latitude")) { shuttle.latitude = reader.nextDouble(); } else if (key.equals("longitude")) { shuttle.longitude = reader.nextDouble(); } else if (key.equals("speed")) { shuttle.speed = reader.nextInt(); } else if (key.equals("timestamp")) { SimpleDateFormat iso_format = new SimpleDateFormat("yyyy-MM-dd HH:mmZ"); try { shuttle.timestamp = iso_format.parse(reader.nextString().replace("T", " ")); } catch (ParseException e) { e.printStackTrace(); } } else if (key.equals("public_status_message")) { shuttle.description = reader.nextString(); } else if (key.equals("cardinal_point")) { shuttle.cardinalPoint = reader.nextString(); } } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); reader.endObject(); Log.d("RPIDataProvider", String.format("Updated Shuttle %S (%S) location...", Integer.toString(shuttle.id), shuttle.name)); return shuttle; }
From source file:es.chatclient.server.messages.adapters.RequestMessageTypeAdapter.java
@Override public RequestMessage read(JsonReader in) throws IOException { final RequestMessage loginRequest = new RequestMessage(); in.beginObject();//from w ww. j a v a 2 s.com in.nextName(); loginRequest.setUserName(in.nextString()); in.nextName(); loginRequest.setUserNick(in.nextString()); in.nextName(); loginRequest.setUserPassword(in.nextString()); in.nextName(); loginRequest.setUserEmail(in.nextString()); in.nextName(); loginRequest.setRequestType(in.nextInt()); in.endObject(); return loginRequest; }
From source file:io.bouquet.v4.GsonFactory.java
License:Apache License
@Override public ApiException read(JsonReader in) throws IOException { in.beginObject();/*from ww w. ja v a2 s. com*/ String message = null; int code = 0; String redirectURL = null; String clientId = null; String type = null; while (in.hasNext()) { switch (in.nextName()) { case "code": code = in.nextInt(); break; case "type": type = in.nextString(); case "error": message = in.nextString(); case "redirectURL": redirectURL = in.nextString(); case "clientId": clientId = in.nextString(); } } ApiException ae = new ApiException(code, message); ae.setType(type); ae.setRedirectURL(redirectURL); ae.setClientId(clientId); return ae; }
From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java
@Override public OpenPlatformAuthGetLicenseInformationResponse read(JsonReader in) throws IOException { OpenPlatformAuthGetLicenseInformationResponse model = new OpenPlatformAuthGetLicenseInformationResponse(); in.beginObject();/* w ww. j a v a 2s. c om*/ while (in.hasNext()) { String key = in.nextName(); switch (key) { case Convention.OPEN_PLATFORM_AUTH_LICENSED_INFORMATION_KEY: readLicensedAccessToken(in, model); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_INFORMATION_KEY: readLicensorInformation(in, model); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_KEY: model.getLicensedAccessToken().setAccessToken(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_EXPIRES_IN_KEY: model.getLicensedAccessToken().setExpiresIn(in.nextInt()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_REFRESH_TOKEN_KEY: model.getLicensedAccessToken().setRefreshToken(in.nextString()); break; default: if (in.hasNext()) { String value = in.nextString(); logger.warn(LOG_UNKNOWN_JSON_KEY, key, value); } } } in.endObject(); return model; }