Exemplo n.º 1
0
 private String nextValue() {
   try {
     tokenType = jsonReader.peek();
     JsonObject peek = stackObj.peek();
     String valueType = peek.getValueType();
     if (!validateArgumentTypes(tokenType, valueType)) {
       log.error(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
       throw new IllegalArgumentException(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
     }
     if (tokenType == JsonToken.STRING) {
       value = jsonReader.nextString();
     } else if (tokenType == JsonToken.BOOLEAN) {
       value = String.valueOf(jsonReader.nextBoolean());
     } else if (tokenType == JsonToken.NUMBER) {
       if (valueType.equals("int")) {
         value = String.valueOf(jsonReader.nextInt());
       } else if (valueType.equals("long")) {
         value = String.valueOf(jsonReader.nextLong());
       } else if (valueType.equals("double")) {
         value = String.valueOf(jsonReader.nextDouble());
       } else if (valueType.equals("float")) {
         value = String.valueOf(jsonReader.nextDouble());
       }
     } else if (tokenType == JsonToken.NULL) {
       jsonReader.nextNull();
       value = null;
     } else {
       log.error("Couldn't read the value, Illegal state exception");
       throw new RuntimeException("Couldn't read the value, Illegal state exception");
     }
   } catch (IOException e) {
     log.error("IO error while reading json stream");
     throw new RuntimeException("IO error while reading json stream");
   }
   return value;
 }
Exemplo n.º 2
0
 private void nextName() throws IOException, XMLStreamException {
   String name = jsonReader.nextName();
   boolean isElementExists = false;
   if (!miniList.isEmpty()) {
     while (!isElementExists && (miniListPointer < miniList.size() || skipMiniListElement)) {
       if (miniListPointer >= miniList.size()) {
         skipMiniListElement = false;
         miniListPointer = 0;
       }
       JsonObject jsonObject = miniList.get(miniListPointer);
       if (jsonObject.getName().equals(name)) {
         isElementExists = true;
         namespace = jsonObject.getNamespaceUri();
         stackObj.push(jsonObject);
         miniList.remove(miniListPointer);
         if (miniListPointer > 0) skipMiniListElement = true;
       } else {
         ++miniListPointer;
       }
       if (miniListPointer > miniList.size() && isElementExists) {
         throw new XMLStreamException(
             JsonConstant.IN_JSON_MESSAGE_NOT_VALID + name + " does not exist in schema");
       }
     }
   } else {
     if (!schemaList.isEmpty()) {
       while (!isElementExists
           && (schemaListPointer < schemaList.size() || skipSchemaListElement)) {
         if (schemaListPointer >= schemaList.size()) {
           skipSchemaListElement = false;
           schemaListPointer = 0;
         }
         JsonObject jsonObject = schemaList.get(schemaListPointer);
         if (jsonObject.getName().equals(name)) {
           isElementExists = true;
           namespace = jsonObject.getNamespaceUri();
           stackObj.push(jsonObject);
           schemaList.remove(schemaListPointer);
           if (schemaListPointer > 0) skipSchemaListElement = true;
         } else {
           ++schemaListPointer;
         }
       }
       if (schemaListPointer > schemaList.size() && !isElementExists) {
         throw new XMLStreamException(
             JsonConstant.IN_JSON_MESSAGE_NOT_VALID + name + " does not exist in schema");
       }
     }
   }
   localName = name;
   value = null;
 }