List of usage examples for com.google.gson.stream JsonReader nextString
public String nextString() throws IOException
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;// w w w . j a v a 2s. c o m ArrayList<String> configSetList = new ArrayList<>(); String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8); StringReader stringReader = new StringReader(configSetString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "collections")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private void parseReply(String aMessage) throws DSException, IOException { String jsonName;//from w ww .j ava2 s. co m Logger appLogger = mAppMgr.getLogger(this, "parseReply"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); int msgCode = 0; String msgString = StringUtils.EMPTY; StringReader stringReader = new StringReader(aMessage); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "exception")) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "msg")) msgString = jsonReader.nextString(); else if (StringUtils.equals(jsonName, "rspCode")) msgCode = jsonReader.nextInt(); else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); if (StringUtils.isNotEmpty(msgString)) throw new DSException(String.format("Solr Exception [%d]: %s", msgCode, msgString)); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private String nextValueAsString(JsonReader aReader) throws IOException { String valueString = StringUtils.EMPTY; JsonToken jsonToken = aReader.peek(); switch (jsonToken) { case BOOLEAN: valueString = StrUtl.booleanToString(aReader.nextBoolean()); break;/* w w w . java 2s . co m*/ case NUMBER: case STRING: valueString = Solr.cleanContent(aReader.nextString()); break; default: aReader.skipValue(); break; } return valueString; }
From source file:com.nridge.ds.solr.SolrConfigSet.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;/*from w w w.j av a 2 s. c om*/ ArrayList<String> configSetList = new ArrayList<>(); String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8); StringReader stringReader = new StringReader(configSetString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "configSets")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private String nextValueAsString(JsonReader aReader) throws IOException { String valueString = StringUtils.EMPTY; JsonToken jsonToken = aReader.peek(); switch (jsonToken) { case BOOLEAN: valueString = StrUtl.booleanToString(aReader.nextBoolean()); break;//from www . j a v a 2 s.c o m case NUMBER: case STRING: valueString = aReader.nextString(); break; default: aReader.skipValue(); break; } return valueString; }
From source file:com.onfido.JSON.java
License:Apache License
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL://from ww w.j a v a 2 s .c o m in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length() - 5) + "Z"; } return OffsetDateTime.parse(date, formatter); } }
From source file:com.onfido.JSON.java
License:Apache License
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL:/*from w w w . j a v a 2s . c o m*/ in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } }
From source file:com.ouyangzn.github.json.DoubleAdapter.java
License:Apache License
@Override public Number read(JsonReader jsonReader) throws IOException { if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull();//from w ww .j a v a 2 s .c o m return null; } try { String value = jsonReader.nextString(); if ("".equals(value)) { return null; } return Double.parseDouble(value); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } }
From source file:com.ouyangzn.github.json.IntegerAdapter.java
License:Apache License
@Override public Number read(JsonReader jsonReader) throws IOException { if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull();/*from w w w . j a v a2 s .com*/ return null; } try { String value = jsonReader.nextString(); if ("".equals(value)) { return null; } return Integer.parseInt(value); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } }
From source file:com.ouyangzn.github.json.LongAdapter.java
License:Apache License
@Override public Number read(JsonReader jsonReader) throws IOException { if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull();// w w w. ja va 2 s .c o m return null; } try { String value = jsonReader.nextString(); if ("".equals(value)) { return null; } return Long.parseLong(value); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } }