Example #1
0
  @SuppressWarnings("unchecked")
  private void processNextNode() {
    if (stateStack.isEmpty()) {
      nextEvent = null;
      return;
    }

    currentItr = stateStack.peek();
    if (currentItr.hasNext()) {
      Object o = currentItr.next();
      if (inMap()) {
        Entry<String, HValue> entry = (Entry<String, HValue>) o;
        key = entry.getKey();
        value = entry.getValue();
      } else {
        key = null;
        value = HValue.initFromObject(o);
      }
      nextEvent = Types.getEventTypeForType(value.getType());
      if (!value.getType().isScalar()) {
        stateStack.push(new IteratorWithType(value));
      }
    } else {
      IteratorWithType iter = stateStack.pop();
      key = null;
      value = iter.getValue();
      nextEvent = (iter.getType() == Type.MAP) ? EventType.END_MAP : EventType.END_ARRAY;
      currentItr = stateStack.isEmpty() ? null : stateStack.peek();
    }
  }
Example #2
0
 HDocumentReader(HValue value) {
   stateStack = new ArrayDeque<>();
   this.key = null;
   this.value = value;
   Type type = value.getType();
   nextEvent = Types.getEventTypeForType(type);
   if (!type.isScalar()) {
     stateStack.push(new IteratorWithType(value));
   }
 }
 @Override
 public EventType next() {
   EventType et = super.next();
   switch (et) {
     case FIELD_NAME:
       currentFieldName = getFieldName();
       calculateCurrentFieldPath();
       break;
     case START_MAP:
       if (currentFieldName != null) {
         fieldSegmentStack.push(currentFieldName);
       }
       break;
     case END_MAP:
       if (!fieldSegmentStack.isEmpty()) {
         fieldSegmentStack.pop();
       }
       break;
     case START_ARRAY:
     case END_ARRAY:
       break;
     default:
       Type mappedType = typeMap.get(currentFieldPath);
       if (mappedType != null) {
         Type currentFieldType = mappedType;
         et = currentEventType = Types.getEventTypeForType(currentFieldType);
         try {
           cacheCurrentValue();
         } catch (JsonParseException jp) {
           throw new IllegalStateException(jp);
         } catch (IOException e) {
           throw new DecodingException(e);
         }
       }
       break;
   }
   return et;
 }