@Test(expected = EntityProviderException.class) public void collectionWithWrongTag() throws Exception { final EntityPropertyInfo info = EntityInfoAggregator.create( MockFacade.getMockEdm().getDefaultEntityContainer().getFunctionImport("AllUsedRoomIds")); new JsonPropertyDeserializer().readCollection(prepareReader("{\"something\":[]}"), info, null); }
public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo, final DeserializerProperties readProperties) throws EntityProviderException { final Object typeMapping = null ; 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); } }
JsonPropertyDeserializer { public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo, final DeserializerProperties readProperties) throws EntityProviderException { final Object typeMapping = null ; 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); } } }
JsonPropertyDeserializer { public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo, final DeserializerProperties readProperties) throws EntityProviderException { final Object typeMapping = null ; 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); } }  }
JsonPropertyDeserializer { public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo, final DeserializerProperties readProperties) throws EntityProviderException { final Object typeMapping = null ; 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); } }  Map<String, Object> readPropertyStandalone(JsonReader reader, final EdmProperty edmProperty,
      final DeserializerProperties readProperties); Map<String, Object> readPropertyStandalone(final JsonReader reader, final EntityPropertyInfo propertyInfo,
      final DeserializerProperties readProperties); List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo,
        final DeserializerProperties readProperties); }
JsonPropertyDeserializer { public List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo, final DeserializerProperties readProperties) throws EntityProviderException { final Object typeMapping = null ; 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); } }  Map<String, Object> readPropertyStandalone(JsonReader reader, final EdmProperty edmProperty,
      final DeserializerProperties readProperties); Map<String, Object> readPropertyStandalone(final JsonReader reader, final EntityPropertyInfo propertyInfo,
      final DeserializerProperties readProperties); List<?> readCollection(JsonReader reader, final EntityPropertyInfo propertyInfo,
        final DeserializerProperties readProperties);  }