List of usage examples for com.google.gson.stream JsonReader skipValue
public void skipValue() throws IOException
From source file:com.miki.webapp.webservicerestful.MikiWsJsonTools.java
/** * Cette methode permet de renvoyer un map contenant les attributs(pass en parametre) et leurs valeurs * @param json les donnes en format json * @param listeAttribut une liste des attributs a chercher dans le Json * @return un Map//from ww w .ja v a 2 s . c o m */ public Map<String, String> getObjetLectureJson(String json, List<String> listeAttribut) { try { if (!listeAttribut.isEmpty()) { final JsonReader reader = new JsonReader(new StringReader(json)); Map<String, String> resultat = new HashMap<>(); reader.beginObject(); while (reader.hasNext()) { final String name = reader.nextName(); int iter = 0; for (String attribut : listeAttribut) { if (name.equals(attribut)) { if (reader.peek() == JsonToken.NULL) { reader.nextNull(); resultat.put(attribut, null); } else { resultat.put(attribut, reader.nextString()); } } else { iter++; } } if (iter == listeAttribut.size()) { reader.skipValue(); } } reader.endObject(); return resultat; } else { return null; } } catch (IOException e) { e.printStackTrace(); System.out.println("Echec de l'opration"); return null; } }
From source file:com.nridge.core.io.gson.DataBagJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a bag/table. * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. */// w w w . j a va 2s. c o m public void load(JsonReader aReader) throws IOException { DataField dataField; String jsonName, jsonValue; aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_NAME_MEMBER_NAME)) mBag.setName(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_TITLE_MEMBER_NAME)) mBag.setTitle(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_FEATURES_ARRAY_NAME)) { aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = aReader.nextString(); mBag.addFeature(jsonName, jsonValue); } aReader.endObject(); } else if (StringUtils.equals(jsonName, IO.JSON_FIELDS_ARRAY_NAME)) { aReader.beginArray(); while (aReader.hasNext()) { dataField = mDataFieldJSON.load(aReader); if (dataField != null) mBag.add(dataField); } aReader.endArray(); } else aReader.skipValue(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.DataTableJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a bag/table. * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. *//*from ww w . j a va 2 s . com*/ public void load(JsonReader aReader) throws IOException { int columnOffset; FieldRow fieldRow; DataField dataField; String jsonName, jsonValue, mvDelimiter; resetContext(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_NAME_MEMBER_NAME)) mDataTable.setName(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_CONTEXT_OBJECT_NAME)) { aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_START_MEMBER_NAME)) mContextStart = aReader.nextInt(); else if (StringUtils.equals(jsonName, IO.JSON_LIMIT_MEMBER_NAME)) mContextLimit = aReader.nextInt(); else if (StringUtils.equals(jsonName, IO.JSON_TOTAL_MEMBER_NAME)) mContextTotal = aReader.nextInt(); else aReader.skipValue(); } aReader.endObject(); } else if (StringUtils.equals(jsonName, IO.JSON_BAG_OBJECT_NAME)) { DataBagJSON dataBagJSON = new DataBagJSON(); dataBagJSON.load(aReader); mDataTable.setColumns(dataBagJSON.getBag()); } else if (StringUtils.equals(jsonName, IO.JSON_ROWS_ARRAY_NAME)) { aReader.beginArray(); while (aReader.hasNext()) { columnOffset = 0; fieldRow = mDataTable.newRow(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_CELL_MEMBER_NAME)) { jsonValue = aReader.nextString(); dataField = mDataTable.getColumn(columnOffset); if (dataField != null) { if (dataField.isMultiValue()) { mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER); if (StringUtils.isNotEmpty(mvDelimiter)) fieldRow.setValues(columnOffset, StrUtl.expandToList(jsonValue, mvDelimiter.charAt(0))); else fieldRow.setValues(columnOffset, StrUtl.expandToList(jsonValue, StrUtl.CHAR_PIPE)); } else fieldRow.setValue(columnOffset, jsonValue); columnOffset++; } } else aReader.skipValue(); } aReader.endObject(); mDataTable.addRow(fieldRow); } aReader.endArray(); } else aReader.skipValue(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.DocumentJSON.java
License:Open Source License
private void loadACL(JsonReader aReader, Document aDocument) throws IOException { String jsonName, aceName, aceValue; HashMap<String, String> docACL = aDocument.getACL(); aReader.beginArray();/*from w w w .j a v a 2 s. c o m*/ while (aReader.hasNext()) { aceName = StringUtils.EMPTY; aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_NAME_MEMBER_NAME)) aceName = aReader.nextString(); else if (StringUtils.equals(jsonName, IO.JSON_VALUE_MEMBER_NAME)) { aceValue = aReader.nextString(); if (StringUtils.isNotEmpty(aceName)) docACL.put(aceName, aceValue); } else aReader.skipValue(); } aReader.endObject(); } aReader.endArray(); }
From source file:com.nridge.core.io.gson.DocumentJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a document and returns * an instance to it./*from ww w. jav a 2 s.co m*/ * * @param aReader Json reader stream instance. * * @return Document instance containing the parsed data. * * @throws java.io.IOException I/O related exception. */ public Document loadDocument(JsonReader aReader) throws IOException { String jsonName, jsonValue; Document document = new Document(IO.XML_DOCUMENT_NODE_NAME); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_NAME_MEMBER_NAME)) document.setName(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_TYPE_MEMBER_NAME)) document.setType(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_VERSION_MEMBER_NAME)) document.setSchemaVersion(Integer.parseInt(aReader.nextString())); else if (StringUtils.equals(jsonName, IO.JSON_TITLE_MEMBER_NAME)) document.setTitle(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_FEATURES_ARRAY_NAME)) { aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = aReader.nextString(); document.addFeature(jsonName, jsonValue); } aReader.endObject(); } else if (StringUtils.equals(jsonName, IO.JSON_TABLE_OBJECT_NAME)) { DataTableJSON dataTableJSON = new DataTableJSON(); dataTableJSON.load(aReader); document.setTable(dataTableJSON.getTable()); } else if (StringUtils.equals(jsonName, IO.JSON_RELATED_ARRAY_NAME)) loadRelated(aReader, document); else if (StringUtils.equals(jsonName, IO.JSON_ACL_ARRAY_NAME)) loadACL(aReader, document); else aReader.skipValue(); } aReader.endObject(); return document; }
From source file:com.nridge.core.io.gson.DocumentOpJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into an internally managed * document operation instance.//from w w w .j ava 2s .co m * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. */ public void load(JsonReader aReader) throws IOException { String jsonName; mCriteria = null; mDocumentList.clear(); mField.clearFeatures(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_FIELD_OBJECT_NAME)) { DataFieldJSON dataFieldJSON = new DataFieldJSON(); mField = dataFieldJSON.load(aReader); } else if (StringUtils.equals(jsonName, IO.JSON_DOCUMENTS_ARRAY_NAME)) { DocumentJSON documentJSON; aReader.beginArray(); while (aReader.hasNext()) { documentJSON = new DocumentJSON(); documentJSON.load(aReader); mDocumentList.add(documentJSON.getDocument()); } aReader.endArray(); } else if (StringUtils.equals(jsonName, IO.JSON_CRITERIA_OBJECT_NAME)) { DSCriteriaJSON dsCriteriaJSON = new DSCriteriaJSON(); dsCriteriaJSON.load(aReader); mCriteria = dsCriteriaJSON.getCriteria(); } else aReader.skipValue(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.DocumentReplyJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into an internally managed * document instance./* w w w . j av a 2 s .com*/ * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. */ public void load(JsonReader aReader) throws IOException { String jsonName; mDocumentList.clear(); mField.clearFeatures(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_FIELD_OBJECT_NAME)) { DataFieldJSON dataFieldJSON = new DataFieldJSON(); mField = dataFieldJSON.load(aReader); } else if (StringUtils.equals(jsonName, IO.JSON_DOCUMENTS_ARRAY_NAME)) { DocumentJSON documentJSON; aReader.beginArray(); while (aReader.hasNext()) { documentJSON = new DocumentJSON(); documentJSON.load(aReader); mDocumentList.add(documentJSON.getDocument()); } aReader.endArray(); } else aReader.skipValue(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.DSCriteriaJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a bag/table. * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. *//*from www. j av a 2 s . c om*/ public void load(JsonReader aReader) throws IOException { DataField dataField; String jsonName, jsonValue, logicalOperator; mDSCriteria.reset(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_NAME_MEMBER_NAME)) mDSCriteria.setName(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_FEATURES_ARRAY_NAME)) { aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = aReader.nextString(); mDSCriteria.addFeature(jsonName, jsonValue); } aReader.endObject(); } else if (StringUtils.equals(jsonName, IO.JSON_FIELDS_ARRAY_NAME)) { aReader.beginArray(); while (aReader.hasNext()) { dataField = mDataFieldJSON.load(aReader); if (dataField != null) { logicalOperator = dataField.getFeature(IO.JSON_OPERATOR_MEMBER_NAME); if (StringUtils.isEmpty(logicalOperator)) logicalOperator = Field.operatorToString(Field.Operator.EQUAL); mDSCriteria.add(dataField, Field.stringToOperator(logicalOperator)); } } aReader.endArray(); } else aReader.skipValue(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.JSONDocument.java
License:Open Source License
/** * Parses an JSON stream and loads it into an internally managed * document instance./*from w w w . ja va2s.co m*/ * * @param aReader Json reader stream instance. * * @throws IOException I/O related exception. */ private void loadDocument(JsonReader aReader, Document aDocument) throws IOException { DataBag dataBag; JsonToken jsonToken; DataField dataField; String jsonName, jsonValue, jsonTitle; aReader.beginObject(); jsonToken = aReader.peek(); while (jsonToken == JsonToken.NAME) { jsonName = aReader.nextName(); jsonTitle = Field.nameToTitle(jsonName); jsonToken = aReader.peek(); switch (jsonToken) { case BOOLEAN: dataBag = aDocument.getBag(); dataField = new DataField(jsonName, jsonTitle, aReader.nextBoolean()); dataBag.add(dataField); break; case NUMBER: dataBag = aDocument.getBag(); jsonValue = aReader.nextString(); if (StringUtils.contains(jsonValue, StrUtl.CHAR_DOT)) dataField = new DataField(jsonName, jsonTitle, Double.valueOf(jsonValue)); else dataField = new DataField(jsonName, jsonTitle, Long.valueOf(jsonValue)); dataBag.add(dataField); break; case STRING: dataBag = aDocument.getBag(); jsonValue = aReader.nextString(); Date dateValue = DatUtl.detectCreateDate(jsonValue); if (dateValue != null) dataField = new DataField(jsonName, jsonTitle, dateValue); else dataField = new DataField(Field.Type.Text, jsonName, jsonTitle, jsonValue); dataBag.add(dataField); break; case NULL: dataBag = aDocument.getBag(); aReader.nextNull(); dataField = new DataField(Field.Type.Text, jsonName, jsonTitle); dataBag.add(dataField); break; case BEGIN_ARRAY: aReader.beginArray(); if (isNextTokenAnObject(aReader)) { Document childDocument = new Document(jsonTitle); childDocument.setName(jsonName); aDocument.addRelationship(jsonTitle, childDocument); loadDocumentArray(aReader, childDocument); } else { dataBag = aDocument.getBag(); dataField = new DataField(Field.Type.Text, jsonName, jsonTitle); jsonToken = aReader.peek(); while (jsonToken != JsonToken.END_ARRAY) { jsonValue = aReader.nextString(); dataField.addValue(jsonValue); jsonToken = aReader.peek(); } dataBag.add(dataField); } aReader.endArray(); break; case BEGIN_OBJECT: Document childDocument = new Document(jsonTitle); childDocument.setName(jsonName); aDocument.addRelationship(jsonTitle, childDocument); loadDocument(aReader, childDocument); break; default: aReader.skipValue(); break; } jsonToken = aReader.peek(); } aReader.endObject(); }
From source file:com.nridge.core.io.gson.RangeJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a field range. * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. *///from w ww. j a v a 2s .c o m public FieldRange load(JsonReader aReader) throws IOException { String jsonName; boolean isFirst = true; Date firstDate = new Date(); long firstLong = Long.MIN_VALUE; int firstInt = Integer.MIN_VALUE; double firstDouble = Double.MIN_VALUE; Field.Type rangeType = Field.Type.Text; FieldRange fieldRange = new FieldRange(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_TYPE_MEMBER_NAME)) rangeType = Field.stringToType(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_DELIMITER_MEMBER_NAME)) fieldRange.setDelimiterChar(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_VALUE_MEMBER_NAME)) fieldRange.setItems(StrUtl.expandToList(aReader.nextString(), fieldRange.getDelimiterChar())); else if (StringUtils.equals(jsonName, "min")) { switch (rangeType) { case Long: if (isFirst) { isFirst = false; firstLong = aReader.nextLong(); } else fieldRange = new FieldRange(aReader.nextLong(), firstLong); break; case Integer: if (isFirst) { isFirst = false; firstInt = aReader.nextInt(); } else fieldRange = new FieldRange(aReader.nextInt(), firstInt); break; case Double: if (isFirst) { isFirst = false; firstDouble = aReader.nextDouble(); } else fieldRange = new FieldRange(aReader.nextDouble(), firstDouble); break; case DateTime: if (isFirst) { isFirst = false; firstDate = Field.createDate(aReader.nextString()); } else fieldRange = new FieldRange(Field.createDate(aReader.nextString()), firstDate); break; default: aReader.skipValue(); break; } } else if (StringUtils.equals(jsonName, "max")) { switch (rangeType) { case Long: if (isFirst) { isFirst = false; firstLong = aReader.nextLong(); } else fieldRange = new FieldRange(firstLong, aReader.nextLong()); break; case Integer: if (isFirst) { isFirst = false; firstInt = aReader.nextInt(); } else fieldRange = new FieldRange(firstInt, aReader.nextInt()); break; case Double: if (isFirst) { isFirst = false; firstDouble = aReader.nextDouble(); } else fieldRange = new FieldRange(firstDouble, aReader.nextDouble()); break; case DateTime: if (isFirst) { isFirst = false; firstDate = Field.createDate(aReader.nextString()); } else fieldRange = new FieldRange(firstDate, Field.createDate(aReader.nextString())); break; default: aReader.skipValue(); break; } } else aReader.skipValue(); } aReader.endObject(); return fieldRange; }