You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/06/24 06:57:44 UTC

[19/23] [OLINGO-317] Rename and move of some packages and classes

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
deleted file mode 100644
index 61e6ac6..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.op.impl.v4;
-
-import java.io.InputStream;
-
-import javax.xml.stream.XMLStreamException;
-
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
-import org.apache.olingo.client.api.op.v4.ODataDeserializer;
-import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
-import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
-import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl;
-import org.apache.olingo.client.core.edm.xml.v4.XMLMetadataImpl;
-import org.apache.olingo.commons.api.data.Delta;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.format.Format;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.api.op.ODataDeserializerException;
-import org.apache.olingo.commons.core.data.AtomDeserializer;
-import org.apache.olingo.commons.core.data.JSONDeltaDeserializer;
-import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
-
-public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
-
-  private final Format format;
-
-  public ODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, final Format format) {
-    super(version, serverMode, format);
-    this.format = format;
-  }
-
-  @Override
-  public XMLMetadata toMetadata(final InputStream input) {
-    try {
-      return new XMLMetadataImpl(getXmlMapper().readValue(input, EdmxImpl.class));
-    } catch (Exception e) {
-      throw new IllegalArgumentException("Could not parse as Edmx document", e);
-    }
-  }
-
-  @Override
-  public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
-    return format == ODataFormat.XML ?
-        new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) :
-        new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input);
-  }
-
-  @Override
-  public ResWrap<Delta> toDelta(final InputStream input) throws ODataDeserializerException {
-    try {
-      return format == ODataPubFormat.ATOM ?
-          new AtomDeserializer(version).delta(input) :
-          new JSONDeltaDeserializer(version, false).toDelta(input);
-    } catch (XMLStreamException e) {
-      throw new ODataDeserializerException(e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
deleted file mode 100644
index ce146e5..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.op.impl.v4;
-
-import java.io.InputStream;
-
-import org.apache.olingo.client.api.op.v4.ODataReader;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.core.op.AbstractODataReader;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.api.op.ODataDeserializerException;
-
-public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
-
-  public ODataReaderImpl(final ODataClient client) {
-    super(client);
-  }
-
-  @Override
-  public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format)
-      throws ODataDeserializerException {
-    return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input));
-  }
-
-  @Override
-  public ODataEntity readEntity(final InputStream input, final ODataPubFormat format)
-      throws ODataDeserializerException {
-    return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
-  }
-
-  @Override
-  public ODataProperty readProperty(final InputStream input, final ODataFormat format)
-      throws ODataDeserializerException {
-    return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input));
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
new file mode 100644
index 0000000..620204a
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
@@ -0,0 +1,528 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization;
+
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.Iterator;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.data.ServiceDocumentItem;
+import org.apache.olingo.client.api.serialization.CommonODataBinder;
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Linked;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Valuable;
+import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.ODataLinkType;
+import org.apache.olingo.commons.api.domain.ODataLinked;
+import org.apache.olingo.commons.api.domain.ODataOperation;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmElement;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmSchema;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.geo.Geospatial;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.serialization.ODataSerializerException;
+import org.apache.olingo.commons.core.data.CollectionValueImpl;
+import org.apache.olingo.commons.core.data.ComplexValueImpl;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.commons.core.data.GeospatialValueImpl;
+import org.apache.olingo.commons.core.data.LinkImpl;
+import org.apache.olingo.commons.core.data.NullValueImpl;
+import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractODataBinder implements CommonODataBinder {
+
+  /**
+   * Logger.
+   */
+  protected final Logger LOG = LoggerFactory.getLogger(AbstractODataBinder.class);
+
+  protected final CommonODataClient<?> client;
+
+  protected AbstractODataBinder(final CommonODataClient<?> client) {
+    this.client = client;
+  }
+
+  @Override
+  public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
+    final ODataServiceDocument serviceDocument = new ODataServiceDocument();
+
+    for (ServiceDocumentItem entitySet : resource.getEntitySets()) {
+      serviceDocument.getEntitySets().
+          put(entitySet.getName(), URIUtils.getURI(resource.getBaseURI(), entitySet.getUrl()));
+    }
+
+    return serviceDocument;
+  }
+
+  @Override
+  public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet) {
+    final EntitySet entitySet = new EntitySetImpl();
+
+    entitySet.setCount(odataEntitySet.getCount());
+
+    final URI next = odataEntitySet.getNext();
+    if (next != null) {
+      entitySet.setNext(next);
+    }
+
+    for (CommonODataEntity entity : odataEntitySet.getEntities()) {
+      entitySet.getEntities().add(getEntity(entity));
+    }
+
+    return entitySet;
+  }
+
+  protected void links(final ODataLinked odataLinked, final Linked linked) {
+    // -------------------------------------------------------------
+    // Append navigation links (handling inline entity / entity set as well)
+    // -------------------------------------------------------------
+    // handle navigation links
+    for (ODataLink link : odataLinked.getNavigationLinks()) {
+      // append link
+      LOG.debug("Append navigation link\n{}", link);
+      linked.getNavigationLinks().add(getLink(link));
+    }
+    // -------------------------------------------------------------
+
+    // -------------------------------------------------------------
+    // Append association links
+    // -------------------------------------------------------------
+    for (ODataLink link : odataLinked.getAssociationLinks()) {
+      LOG.debug("Append association link\n{}", link);
+      linked.getAssociationLinks().add(getLink(link));
+    }
+    // -------------------------------------------------------------
+  }
+
+  @Override
+  public Entity getEntity(final CommonODataEntity odataEntity) {
+    final Entity entity = new EntityImpl();
+
+    entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());
+
+    // -------------------------------------------------------------
+    // Add edit and self link
+    // -------------------------------------------------------------
+    final URI odataEditLink = odataEntity.getEditLink();
+    if (odataEditLink != null) {
+      final LinkImpl editLink = new LinkImpl();
+      editLink.setTitle(entity.getType());
+      editLink.setHref(odataEditLink.toASCIIString());
+      editLink.setRel(Constants.EDIT_LINK_REL);
+      entity.setEditLink(editLink);
+    }
+
+    if (odataEntity.isReadOnly()) {
+      final LinkImpl selfLink = new LinkImpl();
+      selfLink.setTitle(entity.getType());
+      selfLink.setHref(odataEntity.getLink().toASCIIString());
+      selfLink.setRel(Constants.SELF_LINK_REL);
+      entity.setSelfLink(selfLink);
+    }
+    // -------------------------------------------------------------
+
+    links(odataEntity, entity);
+
+    // -------------------------------------------------------------
+    // Append edit-media links
+    // -------------------------------------------------------------
+    for (ODataLink link : odataEntity.getMediaEditLinks()) {
+      LOG.debug("Append edit-media link\n{}", link);
+      entity.getMediaEditLinks().add(getLink(link));
+    }
+    // -------------------------------------------------------------
+
+    if (odataEntity.isMediaEntity()) {
+      entity.setMediaContentSource(odataEntity.getMediaContentSource());
+      entity.setMediaContentType(odataEntity.getMediaContentType());
+      entity.setMediaETag(odataEntity.getMediaETag());
+    }
+
+    for (CommonODataProperty property : odataEntity.getProperties()) {
+      entity.getProperties().add(getProperty(property));
+    }
+
+    return entity;
+  }
+
+  @Override
+  public Link getLink(final ODataLink link) {
+    final Link linkResource = new LinkImpl();
+    linkResource.setRel(link.getRel());
+    linkResource.setTitle(link.getName());
+    linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
+    linkResource.setType(link.getType().toString());
+    linkResource.setMediaETag(link.getMediaETag());
+
+    if (link instanceof ODataInlineEntity) {
+      // append inline entity
+      final CommonODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
+      LOG.debug("Append in-line entity\n{}", inlineEntity);
+
+      linkResource.setInlineEntity(getEntity(inlineEntity));
+    } else if (link instanceof ODataInlineEntitySet) {
+      // append inline entity set
+      final CommonODataEntitySet InlineEntitySet = ((ODataInlineEntitySet) link).getEntitySet();
+      LOG.debug("Append in-line entity set\n{}", InlineEntitySet);
+
+      linkResource.setInlineEntitySet(getEntitySet(InlineEntitySet));
+    }
+
+    return linkResource;
+  }
+
+  protected Value getValue(final ODataValue value) {
+    Value valueResource = null;
+
+    if (value == null) {
+      valueResource = new NullValueImpl();
+    } else if (value.isPrimitive()) {
+      valueResource = value.asPrimitive().getTypeKind().isGeospatial()
+          ? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
+          : new PrimitiveValueImpl(value.asPrimitive().toString());
+    } else if (value.isComplex()) {
+      final ODataComplexValue<? extends CommonODataProperty> _value = value.asComplex();
+      valueResource = new ComplexValueImpl();
+
+      for (final Iterator<? extends CommonODataProperty> itor = _value.iterator(); itor.hasNext();) {
+        valueResource.asComplex().get().add(getProperty(itor.next()));
+      }
+    } else if (value.isCollection()) {
+      final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
+      valueResource = new CollectionValueImpl();
+
+      for (final Iterator<? extends ODataValue> itor = _value.iterator(); itor.hasNext();) {
+        valueResource.asCollection().get().add(getValue(itor.next()));
+      }
+    }
+
+    return valueResource;
+  }
+
+  protected abstract boolean add(CommonODataEntitySet entitySet, CommonODataEntity entity);
+
+  @Override
+  public CommonODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
+    if (LOG.isDebugEnabled()) {
+      final StringWriter writer = new StringWriter();
+      try {
+        client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
+      } catch (final ODataSerializerException e) {}
+      writer.flush();
+      LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
+    }
+
+    final URI base = resource.getContextURL() == null
+        ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+
+    final URI next = resource.getPayload().getNext();
+
+    final CommonODataEntitySet entitySet = next == null
+        ? client.getObjectFactory().newEntitySet()
+        : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));
+
+    if (resource.getPayload().getCount() != null) {
+      entitySet.setCount(resource.getPayload().getCount());
+    }
+
+    for (Entity entityResource : resource.getPayload().getEntities()) {
+      add(entitySet, getODataEntity(
+          new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
+    }
+
+    return entitySet;
+  }
+
+  protected void odataNavigationLinks(final EdmType edmType,
+      final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
+
+    for (Link link : linked.getNavigationLinks()) {
+      final Entity inlineEntity = link.getInlineEntity();
+      final EntitySet inlineEntitySet = link.getInlineEntitySet();
+
+      if (inlineEntity == null && inlineEntitySet == null) {
+        ODataLinkType linkType = null;
+        if (edmType instanceof EdmStructuredType) {
+          final EdmNavigationProperty navProp = ((EdmStructuredType) edmType).getNavigationProperty(link.getTitle());
+          if (navProp != null) {
+            linkType = navProp.isCollection()
+                ? ODataLinkType.ENTITY_SET_NAVIGATION
+                : ODataLinkType.ENTITY_NAVIGATION;
+          }
+        }
+        if (linkType == null) {
+          linkType = link.getType() == null
+              ? ODataLinkType.ENTITY_NAVIGATION
+              : ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
+        }
+
+        odataLinked.addLink(linkType == ODataLinkType.ENTITY_NAVIGATION
+            ? client.getObjectFactory().
+                newEntityNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref()))
+            : client.getObjectFactory().
+                newEntitySetNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
+      } else if (inlineEntity != null) {
+        odataLinked.addLink(new ODataInlineEntity(client.getServiceVersion(),
+            URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(),
+            getODataEntity(new ResWrap<Entity>(
+                inlineEntity.getBaseURI() == null ? base : inlineEntity.getBaseURI(),
+                metadataETag,
+                inlineEntity))));
+      } else {
+        odataLinked.addLink(new ODataInlineEntitySet(client.getServiceVersion(),
+            URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(),
+            getODataEntitySet(new ResWrap<EntitySet>(
+                inlineEntitySet.getBaseURI() == null ? base : inlineEntitySet.getBaseURI(),
+                metadataETag,
+                inlineEntitySet))));
+      }
+    }
+  }
+
+  /**
+   * Infer type name from various sources of information including Edm and context URL, if available.
+   *
+   * @param contextURL context URL
+   * @param metadataETag metadata ETag
+   * @return Edm type information
+   */
+  private EdmType findType(final ContextURL contextURL, final String metadataETag) {
+    EdmType type = null;
+
+    if (client instanceof EdmEnabledODataClient && contextURL != null) {
+      final Edm edm = ((EdmEnabledODataClient) client).getEdm(metadataETag);
+
+      if (contextURL.getDerivedEntity() == null) {
+        for (EdmSchema schema : edm.getSchemas()) {
+          final EdmEntityContainer container = schema.getEntityContainer();
+          if (container != null) {
+            EdmBindingTarget bindingTarget = container.getEntitySet(contextURL.getEntitySetOrSingletonOrType());
+            if (bindingTarget == null) {
+              bindingTarget = container.getSingleton(contextURL.getEntitySetOrSingletonOrType());
+            }
+            if (bindingTarget != null) {
+              if (contextURL.getNavOrPropertyPath() == null) {
+                type = bindingTarget.getEntityType();
+              } else {
+                final EdmNavigationProperty navProp = bindingTarget.getEntityType().
+                    getNavigationProperty(contextURL.getNavOrPropertyPath());
+
+                type = navProp == null
+                    ? bindingTarget.getEntityType()
+                    : navProp.getType();
+              }
+            }
+          }
+        }
+        if (type == null) {
+          type = new EdmTypeInfo.Builder().setEdm(edm).
+              setTypeExpression(contextURL.getEntitySetOrSingletonOrType()).build().getType();
+        }
+      } else {
+        type = edm.getEntityType(new FullQualifiedName(contextURL.getDerivedEntity()));
+      }
+    }
+
+    return type;
+  }
+
+  @Override
+  public CommonODataEntity getODataEntity(final ResWrap<Entity> resource) {
+    if (LOG.isDebugEnabled()) {
+      final StringWriter writer = new StringWriter();
+      try {
+        client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
+      } catch (final ODataSerializerException e) {}
+      writer.flush();
+      LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
+    }
+
+    final URI base = resource.getContextURL() == null
+        ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+
+    final EdmType edmType = findType(resource.getContextURL(), resource.getMetadataETag());
+    FullQualifiedName typeName = null;
+    if (resource.getPayload().getType() == null) {
+      if (edmType != null) {
+        typeName = edmType.getFullQualifiedName();
+      }
+    } else {
+      typeName = new FullQualifiedName(resource.getPayload().getType());
+    }
+
+    final CommonODataEntity entity = resource.getPayload().getSelfLink() == null
+        ? client.getObjectFactory().newEntity(typeName)
+        : client.getObjectFactory().newEntity(typeName,
+            URIUtils.getURI(base, resource.getPayload().getSelfLink().getHref()));
+
+    if (StringUtils.isNotBlank(resource.getPayload().getETag())) {
+      entity.setETag(resource.getPayload().getETag());
+    }
+
+    if (resource.getPayload().getEditLink() != null) {
+      entity.setEditLink(URIUtils.getURI(base, resource.getPayload().getEditLink().getHref()));
+    }
+
+    for (Link link : resource.getPayload().getAssociationLinks()) {
+      entity.addLink(client.getObjectFactory().
+          newAssociationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
+    }
+
+    odataNavigationLinks(edmType, resource.getPayload(), entity, resource.getMetadataETag(), base);
+
+    for (Link link : resource.getPayload().getMediaEditLinks()) {
+      entity.addLink(client.getObjectFactory().
+          newMediaEditLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
+    }
+
+    for (ODataOperation operation : resource.getPayload().getOperations()) {
+      operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
+      entity.getOperations().add(operation);
+    }
+
+    if (resource.getPayload().isMediaEntity()) {
+      entity.setMediaEntity(true);
+      entity.setMediaContentSource(URIUtils.getURI(base, resource.getPayload().getMediaContentSource()));
+      entity.setMediaContentType(resource.getPayload().getMediaContentType());
+      entity.setMediaETag(resource.getPayload().getMediaETag());
+    }
+
+    for (Property property : resource.getPayload().getProperties()) {
+      EdmType propertyType = null;
+      if (edmType instanceof EdmEntityType) {
+        final EdmElement edmProperty = ((EdmEntityType) edmType).getProperty(property.getName());
+        if (edmProperty != null) {
+          propertyType = edmProperty.getType();
+        }
+      }
+      add(entity, getODataProperty(propertyType, property));
+    }
+
+    return entity;
+  }
+
+  protected EdmTypeInfo buildTypeInfo(final ContextURL contextURL, final String metadataETag,
+      final String propertyName, final String propertyType) {
+
+    FullQualifiedName typeName = null;
+    final EdmType type = findType(contextURL, metadataETag);
+    if (type instanceof EdmStructuredType) {
+      final EdmProperty edmProperty = ((EdmStructuredType) type).getStructuralProperty(propertyName);
+      if (edmProperty != null) {
+        typeName = edmProperty.getType().getFullQualifiedName();
+      }
+    }
+    if (typeName == null && type != null) {
+      typeName = type.getFullQualifiedName();
+    }
+
+    return buildTypeInfo(typeName, propertyType);
+  }
+
+  protected EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) {
+    EdmTypeInfo typeInfo = null;
+    if (typeName == null) {
+      if (propertyType != null) {
+        typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
+      }
+    } else {
+      if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) {
+        typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
+      } else {
+        typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
+      }
+    }
+    return typeInfo;
+  }
+
+  protected abstract CommonODataProperty getODataProperty(EdmType type, Property resource);
+
+  protected ODataValue getODataValue(final FullQualifiedName type,
+      final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
+
+    ODataValue value = null;
+    if (valuable.getValue().isGeospatial()) {
+      value = client.getObjectFactory().newPrimitiveValueBuilder().
+          setValue(valuable.getValue().asGeospatial().get()).
+          setType(type == null
+              || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
+              || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
+              ? valuable.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
+              : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+    } else if (valuable.getValue().isPrimitive()) {
+      value = client.getObjectFactory().newPrimitiveValueBuilder().
+          setText(valuable.getValue().asPrimitive().get()).
+          setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
+              ? null
+              : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+    } else if (valuable.getValue().isComplex()) {
+      value = client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
+
+      for (Property property : valuable.getValue().asComplex().get()) {
+        value.asComplex().add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
+      }
+    } else if (valuable.getValue().isCollection()) {
+      value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
+
+      for (Value _value : valuable.getValue().asCollection().get()) {
+        final Property fake = new PropertyImpl();
+        fake.setValue(_value);
+        value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
+      }
+    }
+
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataDeserializer.java
new file mode 100644
index 0000000..18850e3
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataDeserializer.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializer;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+import org.apache.olingo.commons.core.serialization.AtomDeserializer;
+import org.apache.olingo.commons.core.serialization.JsonDeserializer;
+
+import com.fasterxml.aalto.stax.InputFactoryImpl;
+import com.fasterxml.aalto.stax.OutputFactoryImpl;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.InjectableValues;
+import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
+import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
+import com.fasterxml.jackson.dataformat.xml.XmlFactory;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+
+public abstract class AbstractODataDeserializer {
+
+  protected final ODataServiceVersion version;
+  protected final ODataDeserializer deserializer;
+
+  public AbstractODataDeserializer(final ODataServiceVersion version, final boolean serverMode, final Format format) {
+    this.version = version;
+    if (format == ODataFormat.XML || format == ODataPubFormat.ATOM) {
+      deserializer = new AtomDeserializer(version);
+    } else {
+      deserializer = new JsonDeserializer(version, serverMode);
+    }
+  }
+
+  public ResWrap<EntitySet> toEntitySet(final InputStream input) throws ODataDeserializerException {
+    return deserializer.toEntitySet(input);
+  }
+
+  public ResWrap<Entity> toEntity(final InputStream input) throws ODataDeserializerException {
+    return deserializer.toEntity(input);
+  }
+
+  public ResWrap<Property> toProperty(final InputStream input) throws ODataDeserializerException {
+    return deserializer.toProperty(input);
+  }
+
+  public ODataError toError(final InputStream input) throws ODataDeserializerException {
+    return deserializer.toError(input);
+  }
+
+  protected XmlMapper getXmlMapper() {
+    final XmlMapper xmlMapper = new XmlMapper(
+        new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
+
+    xmlMapper.setInjectableValues(new InjectableValues.Std().
+        addValue(ODataServiceVersion.class, version).
+        addValue(Boolean.class, Boolean.FALSE));
+
+    xmlMapper.addHandler(new DeserializationProblemHandler() {
+      @Override
+      public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
+          final com.fasterxml.jackson.databind.JsonDeserializer<?> deserializer,
+          final Object beanOrClass, final String propertyName)
+          throws IOException, JsonProcessingException {
+
+        // skip any unknown property
+        ctxt.getParser().skipChildren();
+        return true;
+      }
+    });
+    return xmlMapper;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
new file mode 100644
index 0000000..94634d4
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
+import org.apache.olingo.client.api.edm.xml.Schema;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.client.api.edm.xml.XMLMetadata;
+import org.apache.olingo.client.api.serialization.CommonODataReader;
+import org.apache.olingo.client.core.edm.EdmClientImpl;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.format.ODataValueFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractODataReader implements CommonODataReader {
+
+  /**
+   * Logger.
+   */
+  protected static final Logger LOG = LoggerFactory.getLogger(AbstractODataReader.class);
+
+  protected final CommonODataClient<?> client;
+
+  protected AbstractODataReader(final CommonODataClient<?> client) {
+    this.client = client;
+  }
+
+  @Override
+  public Edm readMetadata(final InputStream input) {
+    return readMetadata(client.getDeserializer(ODataFormat.XML).toMetadata(input).getSchemaByNsOrAlias());
+  }
+
+  @Override
+  public Edm readMetadata(final Map<String, Schema> xmlSchemas) {
+    return new EdmClientImpl(client.getServiceVersion(), xmlSchemas);
+  }
+
+  @Override
+  public ODataServiceDocument readServiceDocument(final InputStream input, final ODataFormat format)
+      throws ODataDeserializerException {
+    return client.getBinder().getODataServiceDocument(
+            client.getDeserializer(format).toServiceDocument(input).getPayload());
+  }
+
+  @Override
+  public ODataError readError(final InputStream inputStream, final ODataFormat format )
+      throws ODataDeserializerException {
+    return client.getDeserializer(format).toError(inputStream);
+  }
+
+  @Override
+  public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference)
+      throws ODataDeserializerException {
+    ResWrap<T> res;
+
+    try {
+      if (ODataEntitySetIterator.class.isAssignableFrom(reference)) {
+        res = new ResWrap<T>(
+                (URI) null,
+                null,
+                reference.cast(new ODataEntitySetIterator<CommonODataEntitySet, CommonODataEntity>(
+                                client, src, ODataPubFormat.fromString(format))));
+      } else if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
+        final ResWrap<EntitySet> resource = client.getDeserializer(ODataPubFormat.fromString(format))
+            .toEntitySet(src);
+        res = new ResWrap<T>(
+                resource.getContextURL(),
+                resource.getMetadataETag(),
+                reference.cast(client.getBinder().getODataEntitySet(resource)));
+      } else if (CommonODataEntity.class.isAssignableFrom(reference)) {
+        final ResWrap<Entity> container = client.getDeserializer(ODataPubFormat.fromString(format)).toEntity(src);
+        res = new ResWrap<T>(
+                container.getContextURL(),
+                container.getMetadataETag(),
+                reference.cast(client.getBinder().getODataEntity(container)));
+      } else if (CommonODataProperty.class.isAssignableFrom(reference)) {
+        final ResWrap<Property> container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src);
+        res = new ResWrap<T>(
+                container.getContextURL(),
+                container.getMetadataETag(),
+                reference.cast(client.getBinder().getODataProperty(container)));
+      } else if (ODataValue.class.isAssignableFrom(reference)) {
+        res = new ResWrap<T>(
+                (URI) null,
+                null,
+                reference.cast(client.getObjectFactory().newPrimitiveValueBuilder().
+                        setType(ODataValueFormat.fromString(format) == ODataValueFormat.TEXT
+                                ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
+                        setText(IOUtils.toString(src)).
+                        build()));
+      } else if (XMLMetadata.class.isAssignableFrom(reference)) {
+        res = new ResWrap<T>(
+                (URI) null,
+                null,
+                reference.cast(readMetadata(src)));
+      } else if (ODataServiceDocument.class.isAssignableFrom(reference)) {
+        final ResWrap<ServiceDocument> resource =
+                client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src);
+        res = new ResWrap<T>(
+                resource.getContextURL(),
+                resource.getMetadataETag(),
+                reference.cast(client.getBinder().getODataServiceDocument(resource.getPayload())));
+      } else if (ODataError.class.isAssignableFrom(reference)) {
+        res = new ResWrap<T>(
+                (URI) null,
+                null,
+                reference.cast(readError(src, ODataFormat.fromString(format))));
+      } else {
+        throw new IllegalArgumentException("Invalid reference type " + reference);
+      }
+    } catch (Exception e) {
+      LOG.warn("Cast error", e);
+      res = null;
+    } finally {
+      if (!ODataEntitySetIterator.class.isAssignableFrom(reference)) {
+        IOUtils.closeQuietly(src);
+      }
+    }
+
+    return res;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java
new file mode 100644
index 0000000..da6c4e4
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.serialization.ODataWriter;
+import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.serialization.ODataSerializerException;
+
+public class ODataWriterImpl implements ODataWriter {
+
+  protected final CommonODataClient<?> client;
+
+  public ODataWriterImpl(final CommonODataClient<?> client) {
+    this.client = client;
+  }
+
+  @Override
+  public InputStream writeEntities(final Collection<CommonODataEntity> entities, final ODataPubFormat format)
+      throws ODataSerializerException {
+    ByteArrayOutputStream output = new ByteArrayOutputStream();
+    OutputStreamWriter writer;
+    try {
+      writer = new OutputStreamWriter(output, Constants.UTF8);
+    } catch (final UnsupportedEncodingException e) {
+      writer = null;
+    }
+    try {
+      for (CommonODataEntity entity : entities) {
+        client.getSerializer(format).write(writer, client.getBinder().getEntity(entity));
+      }
+
+      return new ByteArrayInputStream(output.toByteArray());
+    } finally {
+      IOUtils.closeQuietly(output);
+    }
+  }
+
+  @Override
+  public InputStream writeEntity(final CommonODataEntity entity, final ODataPubFormat format)
+      throws ODataSerializerException {
+    return writeEntities(Collections.<CommonODataEntity>singleton(entity), format);
+  }
+
+  @Override
+  public InputStream writeProperty(final CommonODataProperty property, final ODataFormat format)
+      throws ODataSerializerException {
+    final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    OutputStreamWriter writer;
+    try {
+      writer = new OutputStreamWriter(output, Constants.UTF8);
+    } catch (final UnsupportedEncodingException e) {
+      writer = null;
+    }
+    try {
+      client.getSerializer(format).write(writer, client.getBinder().getProperty(property));
+
+      return new ByteArrayInputStream(output.toByteArray());
+    } finally {
+      IOUtils.closeQuietly(output);
+    }
+  }
+
+  @Override
+  public InputStream writeLink(final ODataLink link, final ODataFormat format) throws ODataSerializerException {
+    final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    OutputStreamWriter writer;
+    try {
+      writer = new OutputStreamWriter(output, Constants.UTF8);
+    } catch (final UnsupportedEncodingException e) {
+      writer = null;
+    }
+    try {
+      client.getSerializer(format).write(writer, client.getBinder().getLink(link));
+
+      return new ByteArrayInputStream(output.toByteArray());
+    } finally {
+      IOUtils.closeQuietly(output);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
new file mode 100644
index 0000000..77ea315
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v3;
+
+import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
+import org.apache.olingo.client.api.serialization.v3.ODataBinder;
+import org.apache.olingo.client.core.serialization.AbstractODataBinder;
+import org.apache.olingo.client.core.v3.ODataClientImpl;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.domain.v3.ODataPropertyImpl;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+
+public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
+
+  public ODataBinderImpl(final ODataClientImpl client) {
+    super(client);
+  }
+
+  @Override
+  public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
+    complex.add(property);
+  }
+
+  @Override
+  public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
+    return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
+  }
+
+  @Override
+  protected boolean add(final CommonODataEntitySet entitySet, final CommonODataEntity entity) {
+    return ((ODataEntitySet) entitySet).getEntities().add((ODataEntity) entity);
+  }
+
+  @Override
+  public Property getProperty(final CommonODataProperty property) {
+    final Property propertyResource = new PropertyImpl();
+    propertyResource.setName(property.getName());
+    propertyResource.setValue(getValue(property.getValue()));
+
+    if (property.hasPrimitiveValue()) {
+      propertyResource.setType(property.getPrimitiveValue().getTypeName());
+    } else if (property.hasComplexValue()) {
+      propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName());
+    } else if (property.hasCollectionValue()) {
+      propertyResource.setType(((ODataProperty) property).getCollectionValue().getTypeName());
+    }
+
+    return propertyResource;
+  }
+
+  @Override
+  public ODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
+    return (ODataEntitySet) super.getODataEntitySet(resource);
+  }
+
+  @Override
+  public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
+    return (ODataEntity) super.getODataEntity(resource);
+  }
+
+  @Override
+  public ODataProperty getODataProperty(final ResWrap<Property> property) {
+    final EdmTypeInfo typeInfo = buildTypeInfo(property.getContextURL(), property.getMetadataETag(),
+            property.getPayload().getName(), property.getPayload().getType());
+
+    return new ODataPropertyImpl(property.getPayload().getName(),
+            getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
+                    property.getPayload(), property.getContextURL(), property.getMetadataETag()));
+  }
+
+  @Override
+  protected ODataProperty getODataProperty(final EdmType type, final Property resource) {
+    final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
+
+    return new ODataPropertyImpl(resource.getName(),
+            getODataValue(typeInfo == null
+                    ? null
+                    : typeInfo.getFullQualifiedName(),
+                    resource, null, null));
+  }
+
+  @Override
+  public ODataLinkCollection getLinkCollection(final LinkCollection linkCollection) {
+    final ODataLinkCollection collection = new ODataLinkCollection(linkCollection.getNext());
+    collection.setLinks(linkCollection.getLinks());
+    return collection;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataDeserializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataDeserializerImpl.java
new file mode 100644
index 0000000..b99d170
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataDeserializerImpl.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v3;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.edm.xml.XMLMetadata;
+import org.apache.olingo.client.api.serialization.v3.ODataDeserializer;
+import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
+import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
+import org.apache.olingo.client.core.edm.xml.v3.EdmxImpl;
+import org.apache.olingo.client.core.edm.xml.v3.XMLMetadataImpl;
+import org.apache.olingo.client.core.serialization.AbstractODataDeserializer;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+import org.apache.olingo.commons.core.serialization.AtomDeserializer;
+import org.apache.olingo.commons.core.serialization.JsonLinkCollectionDeserializer;
+
+public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
+
+  private final Format format;
+
+  public ODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, final Format format) {
+    super(version, serverMode, format);
+    this.format = format;
+  }
+
+  @Override
+  public XMLMetadata toMetadata(final InputStream input) {
+    try {
+      return new XMLMetadataImpl(getXmlMapper().readValue(input, EdmxImpl.class));
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse as Edmx document", e);
+    }
+  }
+
+  @Override
+  public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
+    return format == ODataFormat.XML ?
+        new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) :
+        new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input);
+  }
+
+  @Override
+  public ResWrap<LinkCollection> toLinkCollection(final InputStream input) throws ODataDeserializerException {
+    try {
+      return format == ODataFormat.XML ?
+          new AtomDeserializer(version).linkCollection(input) :
+          new JsonLinkCollectionDeserializer(version, false).toLinkCollection(input);
+    } catch (final XMLStreamException e) {
+      throw new ODataDeserializerException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataReaderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataReaderImpl.java
new file mode 100644
index 0000000..2297d4d
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataReaderImpl.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v3;
+
+import java.io.InputStream;
+
+import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.client.api.serialization.v3.ODataReader;
+import org.apache.olingo.client.api.v3.ODataClient;
+import org.apache.olingo.client.core.serialization.AbstractODataReader;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+
+public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
+
+  public ODataReaderImpl(final ODataClient client) {
+    super(client);
+  }
+
+  @Override
+  public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input));
+  }
+
+  @Override
+  public ODataEntity readEntity(final InputStream input, final ODataPubFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
+  }
+
+  @Override
+  public ODataProperty readProperty(final InputStream input, final ODataFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input));
+  }
+
+  @Override
+  public ODataLinkCollection readLinks(final InputStream input, final ODataFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getLinkCollection(
+            ((ODataClient) client).getDeserializer(format).toLinkCollection(input).getPayload());
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference)
+      throws ODataDeserializerException {
+    if (ODataLinkCollection.class.isAssignableFrom(reference)) {
+      final ResWrap<LinkCollection> container =
+              ((ODataClient) client).getDeserializer(ODataFormat.fromString(format)).toLinkCollection(src);
+
+      return new ResWrap<T>(
+              container.getContextURL(),
+              container.getMetadataETag(),
+              (T) ((ODataClient) client).getBinder().getLinkCollection(container.getPayload()));
+    } else {
+      return super.read(src, format, reference);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
new file mode 100644
index 0000000..2362a9a
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
@@ -0,0 +1,405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v4;
+
+import java.net.URI;
+
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.data.ServiceDocumentItem;
+import org.apache.olingo.client.api.serialization.v4.ODataBinder;
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.serialization.AbstractODataBinder;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.data.Annotatable;
+import org.apache.olingo.commons.api.data.Annotation;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.DeletedEntity;
+import org.apache.olingo.commons.api.data.Delta;
+import org.apache.olingo.commons.api.data.DeltaLink;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Linked;
+import org.apache.olingo.commons.api.data.LinkedComplexValue;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Valuable;
+import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLinked;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v4.ODataAnnotatable;
+import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
+import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity.Reason;
+import org.apache.olingo.commons.api.domain.v4.ODataDelta;
+import org.apache.olingo.commons.api.domain.v4.ODataDeltaLink;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataLink;
+import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.domain.v4.ODataValuable;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.data.AnnotationImpl;
+import org.apache.olingo.commons.core.data.EnumValueImpl;
+import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.domain.v4.ODataAnnotationImpl;
+import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
+import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
+import org.apache.olingo.commons.core.domain.v4.ODataPropertyImpl;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+
+public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
+
+  public ODataBinderImpl(final ODataClient client) {
+    super(client);
+  }
+
+  @Override
+  public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
+    complex.add(property);
+  }
+
+  @Override
+  public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
+    return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
+  }
+
+  @Override
+  protected boolean add(final CommonODataEntitySet entitySet, final CommonODataEntity entity) {
+    return ((ODataEntitySet) entitySet).getEntities().add((ODataEntity) entity);
+  }
+
+  @Override
+  public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
+    final ODataServiceDocument serviceDocument = super.getODataServiceDocument(resource);
+
+    for (ServiceDocumentItem functionImport : resource.getFunctionImports()) {
+      serviceDocument.getFunctionImports().put(
+              functionImport.getName() == null ? functionImport.getUrl() : functionImport.getName(),
+              URIUtils.getURI(resource.getBaseURI(), functionImport.getUrl()));
+    }
+    for (ServiceDocumentItem singleton : resource.getSingletons()) {
+      serviceDocument.getSingletons().put(
+              singleton.getName() == null ? singleton.getUrl() : singleton.getName(),
+              URIUtils.getURI(resource.getBaseURI(), singleton.getUrl()));
+    }
+    for (ServiceDocumentItem sdoc : resource.getRelatedServiceDocuments()) {
+      serviceDocument.getRelatedServiceDocuments().put(
+              sdoc.getName() == null ? sdoc.getUrl() : sdoc.getName(),
+              URIUtils.getURI(resource.getBaseURI(), sdoc.getUrl()));
+    }
+
+    return serviceDocument;
+  }
+
+  private void updateValuable(final Valuable propertyResource, final ODataValuable odataValuable) {
+
+    propertyResource.setValue(getValue(odataValuable.getValue()));
+
+    if (odataValuable.hasPrimitiveValue()) {
+      propertyResource.setType(odataValuable.getPrimitiveValue().getTypeName());
+    } else if (odataValuable.hasEnumValue()) {
+      propertyResource.setType(odataValuable.getEnumValue().getTypeName());
+    } else if (odataValuable.hasComplexValue()) {
+      propertyResource.setType(odataValuable.getComplexValue().getTypeName());
+    } else if (odataValuable.hasCollectionValue()) {
+      propertyResource.setType(odataValuable.getCollectionValue().getTypeName());
+    }
+  }
+
+  private void annotations(final ODataAnnotatable odataAnnotatable, final Annotatable annotatable) {
+
+    for (ODataAnnotation odataAnnotation : odataAnnotatable.getAnnotations()) {
+      final Annotation annotation = new AnnotationImpl();
+
+      annotation.setTerm(odataAnnotation.getTerm());
+      annotation.setType(odataAnnotation.getValue().getTypeName());
+      updateValuable(annotation, odataAnnotation);
+
+      annotatable.getAnnotations().add(annotation);
+    }
+  }
+
+  @Override
+  public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet) {
+    final EntitySet entitySet = super.getEntitySet(odataEntitySet);
+    entitySet.setDeltaLink(((ODataEntitySet) odataEntitySet).getDeltaLink());
+    annotations((ODataEntitySet) odataEntitySet, entitySet);
+    return entitySet;
+  }
+
+  @Override
+  protected void links(final ODataLinked odataLinked, final Linked linked) {
+    super.links(odataLinked, linked);
+
+    for (Link link : linked.getNavigationLinks()) {
+      final org.apache.olingo.commons.api.domain.ODataLink odataLink = odataLinked.getNavigationLink(link.getTitle());
+      if (!(odataLink instanceof ODataInlineEntity) && !(odataLink instanceof ODataInlineEntitySet)) {
+        annotations((ODataLink) odataLink, link);
+      }
+    }
+  }
+
+  @Override
+  public Entity getEntity(final CommonODataEntity odataEntity) {
+    final Entity entity = super.getEntity(odataEntity);
+    entity.setId(((ODataEntity) odataEntity).getId());
+    annotations((ODataEntity) odataEntity, entity);
+    return entity;
+  }
+
+  @Override
+  public Property getProperty(final CommonODataProperty property) {
+    final ODataProperty _property = (ODataProperty) property;
+
+    final Property propertyResource = new PropertyImpl();
+    propertyResource.setName(_property.getName());
+    updateValuable(propertyResource, _property);
+    annotations(_property, propertyResource);
+
+    return propertyResource;
+  }
+
+  @Override
+  protected Value getValue(final ODataValue value) {
+    Value valueResource;
+    if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
+            && ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) {
+
+      valueResource = new EnumValueImpl(
+              ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum().getValue());
+    } else {
+      valueResource = super.getValue(value);
+
+      if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
+              && ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isLinkedComplex()) {
+
+        final LinkedComplexValue lcValueResource = new LinkedComplexValueImpl();
+        lcValueResource.get().addAll(valueResource.asComplex().get());
+
+        final ODataLinkedComplexValue linked =
+                ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asLinkedComplex();
+        annotations(linked, lcValueResource);
+        links(linked, lcValueResource);
+
+        valueResource = lcValueResource;
+      }
+    }
+    return valueResource;
+  }
+
+  private void odataAnnotations(final Annotatable annotatable, final ODataAnnotatable odataAnnotatable) {
+    for (Annotation annotation : annotatable.getAnnotations()) {
+      FullQualifiedName fqn = null;
+      if (client instanceof EdmEnabledODataClient) {
+        final EdmTerm term = ((EdmEnabledODataClient) client).getEdm(null).
+                getTerm(new FullQualifiedName(annotation.getTerm()));
+        if (term != null) {
+          fqn = term.getType().getFullQualifiedName();
+        }
+      }
+
+      if (fqn == null && annotation.getType() != null) {
+        final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build();
+        if (typeInfo.isPrimitiveType()) {
+          fqn = typeInfo.getPrimitiveTypeKind().getFullQualifiedName();
+        }
+      }
+
+      final ODataAnnotation odataAnnotation = new ODataAnnotationImpl(annotation.getTerm(),
+              (org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(fqn, annotation, null, null));
+      odataAnnotatable.getAnnotations().add(odataAnnotation);
+    }
+  }
+
+  @Override
+  public ODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
+    final ODataEntitySet entitySet = (ODataEntitySet) super.getODataEntitySet(resource);
+
+    if (resource.getPayload().getDeltaLink() != null) {
+      final URI base = resource.getContextURL() == null
+              ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+      entitySet.setDeltaLink(URIUtils.getURI(base, resource.getPayload().getDeltaLink()));
+    }
+    odataAnnotations(resource.getPayload(), entitySet);
+
+    return entitySet;
+  }
+
+  @Override
+  protected void odataNavigationLinks(final EdmType edmType,
+          final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
+
+    super.odataNavigationLinks(edmType, linked, odataLinked, metadataETag, base);
+    for (org.apache.olingo.commons.api.domain.ODataLink link : odataLinked.getNavigationLinks()) {
+      if (!(link instanceof ODataInlineEntity) && !(link instanceof ODataInlineEntitySet)) {
+        odataAnnotations(linked.getNavigationLink(link.getName()), (ODataAnnotatable) link);
+      }
+    }
+  }
+
+  @Override
+  public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
+    final ODataEntity entity = (ODataEntity) super.getODataEntity(resource);
+
+    entity.setId(resource.getPayload().getId());
+    odataAnnotations(resource.getPayload(), entity);
+
+    return entity;
+  }
+
+  @Override
+  public ODataProperty getODataProperty(final ResWrap<Property> resource) {
+    final Property payload = resource.getPayload();
+    final EdmTypeInfo typeInfo = buildTypeInfo(resource.getContextURL(), resource.getMetadataETag(),
+        payload.getName(), payload.getType());
+
+    final ODataProperty property = new ODataPropertyImpl(payload.getName(),
+        getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
+            payload, resource.getContextURL(), resource.getMetadataETag()));
+    odataAnnotations(payload, property);
+
+    return property;
+  }
+
+  @Override
+  protected ODataProperty getODataProperty(final EdmType type, final Property resource) {
+    final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
+
+    final ODataProperty property = new ODataPropertyImpl(resource.getName(),
+            getODataValue(typeInfo == null
+                    ? null
+                    : typeInfo.getFullQualifiedName(),
+                    resource, null, null));
+    odataAnnotations(resource, property);
+
+    return property;
+  }
+
+  @Override
+  protected ODataValue getODataValue(final FullQualifiedName type,
+          final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
+
+    // fixes enum values treated as primitive when no type information is available
+    if (client instanceof EdmEnabledODataClient && type != null) {
+      final EdmEnumType edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getEnumType(type);
+      if (valuable.getValue().isPrimitive() && edmType != null) {
+        valuable.setValue(new EnumValueImpl(valuable.getValue().asPrimitive().get()));
+      }
+    }
+
+    ODataValue value;
+    if (valuable.getValue().isEnum()) {
+      value = ((ODataClient) client).getObjectFactory().newEnumValue(type == null ? null : type.toString(),
+              valuable.getValue().asEnum().get());
+    } else if (valuable.getValue().isLinkedComplex()) {
+      final ODataLinkedComplexValue lcValue =
+              ((ODataClient) client).getObjectFactory().newLinkedComplexValue(type == null ? null : type.toString());
+
+      for (Property property : valuable.getValue().asLinkedComplex().get()) {
+        lcValue.add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
+      }
+
+      EdmComplexType edmType = null;
+      if (client instanceof EdmEnabledODataClient && type != null) {
+        edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
+      }
+
+      odataNavigationLinks(edmType, valuable.getValue().asLinkedComplex(), lcValue, metadataETag,
+              contextURL == null ? null : contextURL.getURI());
+      odataAnnotations(valuable.getValue().asLinkedComplex(), lcValue);
+
+      value = lcValue;
+    } else {
+      value = super.getODataValue(type, valuable, contextURL, metadataETag);
+    }
+
+    return value;
+  }
+
+  @Override
+  public ODataDelta getODataDelta(final ResWrap<Delta> resource) {
+    final URI base = resource.getContextURL() == null
+            ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+
+    final URI next = resource.getPayload().getNext();
+
+    final ODataDelta delta = next == null
+            ? ((ODataClient) client).getObjectFactory().newDelta()
+            : ((ODataClient) client).getObjectFactory().newDelta(URIUtils.getURI(base, next.toASCIIString()));
+
+    if (resource.getPayload().getCount() != null) {
+      delta.setCount(resource.getPayload().getCount());
+    }
+
+    if (resource.getPayload().getDeltaLink() != null) {
+      delta.setDeltaLink(URIUtils.getURI(base, resource.getPayload().getDeltaLink()));
+    }
+
+    for (Entity entityResource : resource.getPayload().getEntities()) {
+      add(delta, getODataEntity(
+              new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
+    }
+    for (DeletedEntity deletedEntity : resource.getPayload().getDeletedEntities()) {
+      final ODataDeletedEntityImpl impl = new ODataDeletedEntityImpl();
+      impl.setId(URIUtils.getURI(base, deletedEntity.getId()));
+      impl.setReason(Reason.valueOf(deletedEntity.getReason().name()));
+
+      delta.getDeletedEntities().add(impl);
+    }
+
+    odataAnnotations(resource.getPayload(), delta);
+
+    for (DeltaLink link : resource.getPayload().getAddedLinks()) {
+      final ODataDeltaLink impl = new ODataDeltaLinkImpl();
+      impl.setRelationship(link.getRelationship());
+      impl.setSource(URIUtils.getURI(base, link.getSource()));
+      impl.setTarget(URIUtils.getURI(base, link.getTarget()));
+
+      odataAnnotations(link, impl);
+
+      delta.getAddedLinks().add(impl);
+    }
+    for (DeltaLink link : resource.getPayload().getDeletedLinks()) {
+      final ODataDeltaLink impl = new ODataDeltaLinkImpl();
+      impl.setRelationship(link.getRelationship());
+      impl.setSource(URIUtils.getURI(base, link.getSource()));
+      impl.setTarget(URIUtils.getURI(base, link.getTarget()));
+
+      odataAnnotations(link, impl);
+
+      delta.getDeletedLinks().add(impl);
+    }
+
+    return delta;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataDeserializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataDeserializerImpl.java
new file mode 100644
index 0000000..f0d4149
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataDeserializerImpl.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v4;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
+import org.apache.olingo.client.api.serialization.v4.ODataDeserializer;
+import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
+import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
+import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl;
+import org.apache.olingo.client.core.edm.xml.v4.XMLMetadataImpl;
+import org.apache.olingo.client.core.serialization.AbstractODataDeserializer;
+import org.apache.olingo.commons.api.data.Delta;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+import org.apache.olingo.commons.core.serialization.AtomDeserializer;
+import org.apache.olingo.commons.core.serialization.JsonDeltaDeserializer;
+
+public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
+
+  private final Format format;
+
+  public ODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, final Format format) {
+    super(version, serverMode, format);
+    this.format = format;
+  }
+
+  @Override
+  public XMLMetadata toMetadata(final InputStream input) {
+    try {
+      return new XMLMetadataImpl(getXmlMapper().readValue(input, EdmxImpl.class));
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse as Edmx document", e);
+    }
+  }
+
+  @Override
+  public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
+    return format == ODataFormat.XML ?
+        new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) :
+        new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input);
+  }
+
+  @Override
+  public ResWrap<Delta> toDelta(final InputStream input) throws ODataDeserializerException {
+    try {
+      return format == ODataPubFormat.ATOM ?
+          new AtomDeserializer(version).delta(input) :
+          new JsonDeltaDeserializer(version, false).toDelta(input);
+    } catch (XMLStreamException e) {
+      throw new ODataDeserializerException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataReaderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataReaderImpl.java
new file mode 100644
index 0000000..c6528f8
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataReaderImpl.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.serialization.v4;
+
+import java.io.InputStream;
+
+import org.apache.olingo.client.api.serialization.v4.ODataReader;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.serialization.AbstractODataReader;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+
+public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
+
+  public ODataReaderImpl(final ODataClient client) {
+    super(client);
+  }
+
+  @Override
+  public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input));
+  }
+
+  @Override
+  public ODataEntity readEntity(final InputStream input, final ODataPubFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
+  }
+
+  @Override
+  public ODataProperty readProperty(final InputStream input, final ODataFormat format)
+      throws ODataDeserializerException {
+    return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input));
+  }
+}