public List readCollection()

in odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonPropertyConsumer.java [87:151]


  public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo,
        final EntityProviderReadProperties readProperties) throws EntityProviderException {
    final Object typeMapping = readProperties == null ? null :
      readProperties.getTypeMappings().get(propertyInfo.getName());
    List<Object> result = new ArrayList<Object>();
    String name = null;
    boolean wrapped = false;
    boolean version2 = false;

    try {
      if (reader.peek() == JsonToken.BEGIN_OBJECT) {
        reader.beginObject();
        name = reader.nextName();
        if (FormatJson.D.equals(name)) {
          wrapped = true;
          if (reader.peek() == JsonToken.BEGIN_OBJECT) {
            reader.beginObject();
            name = reader.nextName();
          } else {
            name = null;
          }
        }
      }
      if (name != null) {
        version2 = true;
        if (FormatJson.METADATA.equals(name)) {
          readAndCheckTypeInfo(reader,
              "Collection(" + propertyInfo.getType().getNamespace() + Edm.DELIMITER
              + propertyInfo.getType().getName() + ")");
          name = reader.nextName();
        }
        if (!FormatJson.RESULTS.equals(name)) {
          throw new EntityProviderException(EntityProviderException.INVALID_PARENT_TAG
              .addContent(FormatJson.RESULTS, name));
        }
      }
      reader.beginArray();
      while (reader.hasNext()) {
        result.add(readPropertyValue(reader, propertyInfo, typeMapping, readProperties));
      }
      reader.endArray();
      if (version2) {
        reader.endObject();
      }
      if (wrapped) {
        reader.endObject();
      }

      if (reader.peek() != JsonToken.END_DOCUMENT) {
        throw new EntityProviderException(EntityProviderException.END_DOCUMENT_EXPECTED
            .addContent(reader.peek().toString()));
      }

      return result;
    } catch (final EdmException e) {
      throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED
          .addContent(e.getClass().getSimpleName()), e);
    } catch (final IOException e) {
      throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED
          .addContent(e.getClass().getSimpleName()), e);
    } catch (final IllegalStateException e) {
      throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED
          .addContent(e.getClass().getSimpleName()), e);
    }
  }