List of usage examples for com.google.gson.stream JsonReader nextString
public String nextString() throws IOException
From source file:data.Task1bData.java
License:Apache License
public ArrayList<String> readConcepts(JsonReader reader) { ArrayList<String> conc = new ArrayList<String>(); int count = 0; try {// w w w . j a v a2 s.c o m reader.beginArray(); while (reader.hasNext()) { String nextString = reader.nextString(); if (!conc.contains(nextString)) conc.add(nextString); } reader.endArray(); } catch (IOException ex) { } return conc; }
From source file:data.Task1bData.java
License:Apache License
public ArrayList<String> readDocuments(JsonReader reader) { ArrayList<String> docs = new ArrayList<String>(); int count = 0; try {//from www. j av a 2 s .c o m reader.beginArray(); while (reader.hasNext()) { String nextString = reader.nextString(); if (!docs.contains(nextString)) docs.add(nextString); } reader.endArray(); } catch (IOException ex) { } return docs; }
From source file:data.TaskADataParser.java
License:Apache License
public static PubMedDocument getNextDocument(JsonReader reader) { String text = null;/* w ww .j a v a2 s.c om*/ String title = null; String pmid = null; String journal = null; String[] meshMajor = null; try { if (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("abstractText")) { text = reader.nextString(); } else if (name.equals("journal")) { journal = reader.nextString(); } else if (name.equals("meshMajor")) { meshMajor = readLabelsArray(reader); } else if (name.equals("pmid")) { pmid = reader.nextString(); } else if (name.equals("title")) { title = reader.nextString(); } else if (name.equals("year")) { reader.skipValue(); } else { System.out.println(name); reader.skipValue(); } } reader.endObject(); } } catch (Exception ex) { } return new PubMedDocument(text, title, pmid, journal, meshMajor); }
From source file:data.TaskADataParser.java
License:Apache License
public static String[] readLabelsArray(JsonReader reader) { String labels[];//from ww w. j ava 2 s. c om ArrayList<String> lab = new ArrayList<String>(); try { reader.beginArray(); while (reader.hasNext()) { String nextString = reader.nextString(); lab.add(nextString); } reader.endArray(); } catch (IOException ex) { } labels = new String[lab.size()]; labels = lab.toArray(labels); return labels; }
From source file:de.dentrassi.eclipse.provider.eclipse.ValueAdapter.java
License:Open Source License
@Override public String read(final JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { return null; }//from ww w . j a v a 2 s. c o m String result = null; in.beginArray(); while (in.hasNext()) { in.beginObject(); while (in.hasNext()) { final String name = in.nextName(); if ("value".equals(name)) { result = in.nextString(); } else { in.skipValue(); } } in.endObject(); } in.endArray(); return result; }
From source file:de.dentrassi.pm.maven.ByteArrayAdapter.java
License:Open Source License
@Override public byte[] read(final JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull();//from w w w .j av a 2 s .c o m return null; } final String data = reader.nextString(); return Base64.getDecoder().decode(data); }
From source file:de.feike.tiingoclient.JSON.java
License:Apache License
@Override public DateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL:// w w w . j a v a 2 s.com in.nextNull(); return null; default: String date = in.nextString(); return parseFormatter.parseDateTime(date); } }
From source file:de.innovationgate.utils.GsonUtils.java
License:Open Source License
/** * Reads the next string value from the reader or null if it is a null value * @param reader The reader//from w w w .j a v a 2s.c om * @return String value or null * @throws IOException */ public static String nextStringOrNull(JsonReader reader) throws IOException { if (reader.peek() != JsonToken.NULL) { return reader.nextString(); } else { reader.nextNull(); return null; } }
From source file:de.loercher.geomodule.cloudant.CloudantGeoSearchStream.java
private void extractEntities(BufferedReader bufferedReader) throws JSONParseException { JsonReader reader = new JsonReader(bufferedReader); try {/*from w w w. j a va 2 s .c o m*/ reader.beginObject(); String arrayName = null; while (reader.hasNext() && !("features".equals(arrayName))) { arrayName = reader.nextName(); if ("bookmark".equals(arrayName)) { bookmark = reader.nextString(); } else if (!("features".equals(arrayName))) { reader.skipValue(); } } if ("features".equals(arrayName)) { reader.beginArray(); while (reader.hasNext()) { Gson gson = new Gson(); CloudantArticleEntity entity = gson.fromJson(reader, CloudantArticleEntity.class); // Duplicates should not be returned if (!(alreadyAvailableIds.contains(entity.getId()))) { bufferedEntities.add(entity); } alreadyAvailableIds.add(entity.getId()); } reader.endArray(); reader.endObject(); reader.close(); } else { JSONParseException e = new JSONParseException( "Parsing of cloudant response failed. Tag 'features' not found. "); log.error(e.getLoggingString()); throw e; } } catch (IOException ex) { JSONParseException e = new JSONParseException("Parsing of cloudant response failed.", ex); log.error(e.getLoggingString()); throw e; } }
From source file:de.m0ep.canvas.gson.ISO8601TypeAdapter.java
License:Open Source License
@Override public Date read(JsonReader reader) throws IOException { if (JsonToken.NULL == reader.peek()) { reader.nextNull();//from w w w . j a v a2 s .c o m return null; } String date = reader.nextString(); Calendar cal = DatatypeConverter.parseDateTime(date); return cal.getTime(); }