/**
  * Method that will construct a parser (possibly a sequence) that contains all given sub-parsers.
  * All parsers given are checked to see if they are sequences: and if so, they will be
  * "flattened", that is, contained parsers are directly added in a new sequence instead of adding
  * sequences within sequences. This is done to minimize delegation depth, ideally only having just
  * a single level of delegation.
  */
 public static JsonParserSequence createFlattened(
     boolean checkForExistingToken, JsonParser first, JsonParser second) {
   if (!(first instanceof JsonParserSequence || second instanceof JsonParserSequence)) {
     return new JsonParserSequence(checkForExistingToken, new JsonParser[] {first, second});
   }
   ArrayList<JsonParser> p = new ArrayList<JsonParser>();
   if (first instanceof JsonParserSequence) {
     ((JsonParserSequence) first).addFlattenedActiveParsers(p);
   } else {
     p.add(first);
   }
   if (second instanceof JsonParserSequence) {
     ((JsonParserSequence) second).addFlattenedActiveParsers(p);
   } else {
     p.add(second);
   }
   return new JsonParserSequence(checkForExistingToken, p.toArray(new JsonParser[p.size()]));
 }
Exemplo n.º 2
0
 protected void addFlattenedActiveParsers(List<JsonParser> result) {
   for (int i = _nextParser - 1, len = _parsers.length; i < len; ++i) {
     JsonParser p = _parsers[i];
     if (p instanceof JsonParserSequence) {
       ((JsonParserSequence) p).addFlattenedActiveParsers(result);
     } else {
       result.add(p);
     }
   }
 }
 @SuppressWarnings("resource")
 protected void addFlattenedActiveParsers(List<JsonParser> listToAddIn) {
   for (int i = _nextParserIndex - 1, len = _parsers.length; i < len; ++i) {
     JsonParser p = _parsers[i];
     if (p instanceof JsonParserSequence) {
       ((JsonParserSequence) p).addFlattenedActiveParsers(listToAddIn);
     } else {
       listToAddIn.add(p);
     }
   }
 }
 private final Object _deserialize(
     JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
     throws IOException {
   Object localObject1;
   if (paramJsonParser.canReadTypeId()) {
     localObject1 = paramJsonParser.getTypeId();
     if (localObject1 != null) {
       paramJsonParser =
           _deserializeWithNativeTypeId(
               paramJsonParser, paramDeserializationContext, localObject1);
     }
   }
   do {
     boolean bool;
     Object localObject2;
     do {
       return paramJsonParser;
       bool = paramJsonParser.isExpectedStartArrayToken();
       String str = _locateTypeId(paramJsonParser, paramDeserializationContext);
       localObject2 = _findDeserializer(paramDeserializationContext, str);
       localObject1 = paramJsonParser;
       if (this._typeIdVisible) {
         localObject1 = paramJsonParser;
         if (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
           localObject1 = new TokenBuffer(null, false);
           ((TokenBuffer) localObject1).writeStartObject();
           ((TokenBuffer) localObject1).writeFieldName(this._typePropertyName);
           ((TokenBuffer) localObject1).writeString(str);
           localObject1 =
               JsonParserSequence.createFlattened(
                   ((TokenBuffer) localObject1).asParser(paramJsonParser), paramJsonParser);
           ((JsonParser) localObject1).nextToken();
         }
       }
       localObject2 =
           ((JsonDeserializer) localObject2)
               .deserialize((JsonParser) localObject1, paramDeserializationContext);
       paramJsonParser = (JsonParser) localObject2;
     } while (!bool);
     paramJsonParser = (JsonParser) localObject2;
   } while (((JsonParser) localObject1).nextToken() == JsonToken.END_ARRAY);
   throw paramDeserializationContext.wrongTokenException(
       (JsonParser) localObject1,
       JsonToken.END_ARRAY,
       "expected closing END_ARRAY after type information and deserialized value");
 }