olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [21/21] git commit: [OLINGO-200] V3 Atom and JSON (de)serializers replaced are now DOM free - all tests succeed
Date Thu, 20 Mar 2014 10:27:15 GMT
[OLINGO-200] V3 Atom and JSON (de)serializers replaced are now DOM free - all tests succeed


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/commit/4431a80d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/tree/4431a80d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/diff/4431a80d

Branch: refs/heads/olingo200
Commit: 4431a80db50c60eb48f47eb59a69f88e4c24f413
Parents: eae72e8 5243d5f
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Mar 20 11:26:41 2014 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Mar 20 11:26:41 2014 +0100

----------------------------------------------------------------------
 .../olingo/fit/utils/AbstractUtilities.java     |  1 +
 .../org/apache/olingo/fit/utils/FSManager.java  |  2 +-
 .../apache/olingo/fit/utils/XMLUtilities.java   |  6 ++--
 .../org/apache/olingo/client/api/Constants.java |  2 ++
 .../client/core/data/AbstractAtomDealer.java    |  7 +++++
 .../client/core/data/AtomDeserializer.java      | 30 ++++++++++++++++++++
 .../olingo/client/core/data/AtomSerializer.java |  9 ++++--
 .../client/core/data/JSONEntrySerializer.java   |  5 +++-
 .../core/data/JSONPropertyDeserializer.java     | 17 ++---------
 .../core/op/impl/AbstractODataBinder.java       |  6 ++--
 .../core/op/impl/AbstractODataDeserializer.java |  9 ++----
 .../client/core/it/AbstractTestITCase.java      |  6 ++--
 pom.xml                                         |  1 -
 13 files changed, 65 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
----------------------------------------------------------------------
diff --cc fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
index 2d93c67,2d93c67..74653a1
--- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
@@@ -423,6 -423,6 +423,7 @@@ public abstract class AbstractUtilitie
  
    public Response createFaultResponse(final String accept, final Exception e) {
      LOG.debug("Create fault response about .... ", e);
++    e.printStackTrace();
  
      final Response.ResponseBuilder builder = Response.serverError();
      if (version == ODataVersion.v3) {

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-api/src/main/java/org/apache/olingo/client/api/Constants.java
----------------------------------------------------------------------
diff --cc lib/client-api/src/main/java/org/apache/olingo/client/api/Constants.java
index 97f833f,091f000..7d9b4a2
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/Constants.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/Constants.java
@@@ -147,6 -128,6 +147,8 @@@ public class Constants 
  
    public static final String ELEM_PROPERTY = "property";
  
++  public static final String ELEM_LINKS = "links";
++
    public static final String ELEM_URI = "uri";
  
    // JSON stuff

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractAtomDealer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractAtomDealer.java
index 64fa3d8,0000000..eb62b44
mode 100644,000000..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractAtomDealer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractAtomDealer.java
@@@ -1,80 -1,0 +1,87 @@@
 +/*
 + * 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.data;
 +
 +import javax.xml.XMLConstants;
 +import javax.xml.namespace.QName;
 +import javax.xml.stream.XMLStreamException;
 +import javax.xml.stream.XMLStreamWriter;
 +import org.apache.commons.lang3.StringUtils;
 +import org.apache.olingo.client.api.Constants;
 +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 +
 +abstract class AbstractAtomDealer {
 +
 +  protected static final String TYPE_TEXT = "text";
 +
 +  protected final ODataServiceVersion version;
 +
 +  protected final QName etagQName;
 +
 +  protected final QName inlineQName;
 +
 +  protected final QName actionQName;
 +
 +  protected final QName propertiesQName;
 +
 +  protected final QName typeQName;
 +
 +  protected final QName nullQName;
 +
 +  protected final QName elementQName;
 +
 +  protected final QName countQName;
 +
++  protected final QName uriQName;
++  protected final QName nextQName;
++
 +  public AbstractAtomDealer(final ODataServiceVersion version) {
 +    this.version = version;
 +
 +    this.etagQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ATTR_ETAG);
 +    this.inlineQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_INLINE);
 +    this.actionQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION);
 +    this.propertiesQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
 +    this.typeQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_TYPE);
 +    this.nullQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_NULL);
 +    this.elementQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.ELEM_ELEMENT);
 +    this.countQName =
 +            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
++    this.uriQName =
++            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.ELEM_URI);
++    this.nextQName =
++            new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.NEXT_LINK_REL);
 +  }
 +
 +  protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
 +    writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM);
 +    writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
 +    writer.writeNamespace(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
 +    writer.writeNamespace(
 +            Constants.PREFIX_DATASERVICES, version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
 +    writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML);
 +    writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
 +  }
 +
 +}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
index d80bcf3,0b5e974..86289f3
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
@@@ -89,162 -74,109 +89,190 @@@ public class AtomDeserializer extends A
      }
    }
  
 -  public AtomEntryImpl entry(final Element input) {
 -    if (!Constants.ATOM_ELEM_ENTRY.equals(input.getNodeName())) {
 -      return null;
 +  private void inline(final XMLEventReader reader, final StartElement start, final LinkImpl
link)
 +          throws XMLStreamException {
 +
 +    boolean foundEndElement = false;
 +    while (reader.hasNext() && !foundEndElement) {
 +      final XMLEvent event = reader.nextEvent();
 +
 +      if (event.isStartElement() && inlineQName.equals(event.asStartElement().getName()))
{
 +        StartElement inline = null;
 +        while (reader.hasNext() && inline == null) {
 +          final XMLEvent innerEvent = reader.peek();
 +          if (innerEvent.isCharacters() && innerEvent.asCharacters().isWhiteSpace())
{
 +            reader.nextEvent();
 +          } else if (innerEvent.isStartElement()) {
 +            inline = innerEvent.asStartElement();
 +          }
 +        }
 +        if (inline != null) {
 +          if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) {
 +            link.setInlineEntry(entry(reader, inline));
 +          }
 +          if (Constants.QNAME_ATOM_ELEM_FEED.equals(inline.getName())) {
 +            link.setInlineFeed(feed(reader, inline));
 +          }
 +        }
 +      }
 +
 +      if (event.isEndElement() && start.getName().equals(event.asEndElement().getName()))
{
 +        foundEndElement = true;
 +      }
      }
 +  }
  
 -    final AtomEntryImpl entry = new AtomEntryImpl();
++  private XMLLinkCollectionImpl linkCollection(final InputStream input) throws XMLStreamException
{
++    final XMLEventReader reader = FACTORY.createXMLEventReader(input);
+ 
 -    common(input, entry);
++    final XMLLinkCollectionImpl linkCollection = new XMLLinkCollectionImpl();
+ 
 -    final String etag = input.getAttribute(Constants.ATOM_ATTR_ETAG);
 -    if (StringUtils.isNotBlank(etag)) {
 -      entry.setETag(etag);
 -    }
++    boolean isURI = false;
++    boolean isNext = false;
++    while (reader.hasNext()) {
++      final XMLEvent event = reader.nextEvent();
++      if (event.isStartElement()) {
++        isURI = uriQName.equals(event.asStartElement().getName());
++        isNext = nextQName.equals(event.asStartElement().getName());
++      }
+ 
 -    final List<Element> categories = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_CATEGORY);
 -    if (!categories.isEmpty()) {
 -      entry.setType(categories.get(0).getAttribute(Constants.ATOM_ATTR_TERM));
++      if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
++        if (isURI) {
++          linkCollection.getLinks().add(URI.create(event.asCharacters().getData()));
++          isURI = false;
++        } else if (isNext) {
++          linkCollection.setNext(URI.create(event.asCharacters().getData()));
++          isNext = false;
++        }
++      }
+     }
+ 
 -    final List<Element> links = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_LINK);
 -    for (Element linkElem : links) {
 -      final LinkImpl link = new LinkImpl();
 -      link.setRel(linkElem.getAttribute(Constants.ATTR_REL));
 -      link.setTitle(linkElem.getAttribute(Constants.ATTR_TITLE));
 -      link.setHref(linkElem.getAttribute(Constants.ATTR_HREF));
 -
 -      if (Constants.SELF_LINK_REL.equals(link.getRel())) {
 -        entry.setSelfLink(link);
 -      } else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
 -        entry.setEditLink(link);
 -      } else if (link.getRel().startsWith(
 -              client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL)))
{
 -
 -        link.setType(linkElem.getAttribute(Constants.ATTR_TYPE));
 -        entry.getNavigationLinks().add(link);
 -
 -        final List<Element> inlines = XMLUtils.getChildElements(linkElem, Constants.ATOM_ELEM_INLINE);
 -        if (!inlines.isEmpty()) {
 -          final List<Element> entries =
 -                  XMLUtils.getChildElements(inlines.get(0), Constants.ATOM_ELEM_ENTRY);
 -          if (!entries.isEmpty()) {
 -            link.setInlineEntry(entry(entries.get(0)));
 -          }
++    return linkCollection;
++  }
+ 
 -          final List<Element> feeds =
 -                  XMLUtils.getChildElements(inlines.get(0), Constants.ATOM_ELEM_FEED);
 -          if (!feeds.isEmpty()) {
 -            link.setInlineFeed(feed(feeds.get(0)));
 -          }
 -        }
 -      } else if (link.getRel().startsWith(
 -              client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL)))
{
 +  private void properties(final XMLEventReader reader, final StartElement start, final AtomEntryImpl
entry)
 +          throws XMLStreamException {
  
 -        entry.getAssociationLinks().add(link);
 -      } else if (link.getRel().startsWith(
 -              client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL)))
{
 +    boolean foundEndProperties = false;
 +    while (reader.hasNext() && !foundEndProperties) {
 +      final XMLEvent event = reader.nextEvent();
  
 -        entry.getMediaEditLinks().add(link);
 +      if (event.isStartElement()) {
 +        entry.getProperties().add(propDeserializer.deserialize(reader, event.asStartElement()));
        }
 -    }
  
 -    final List<Element> authors = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_AUTHOR);
 -    if (!authors.isEmpty()) {
 -      final AtomEntryImpl.Author author = new AtomEntryImpl.Author();
 -      for (Node child : XMLUtils.getChildNodes(input, Node.ELEMENT_NODE)) {
 -        if (Constants.ATOM_ELEM_AUTHOR_NAME.equals(XMLUtils.getSimpleName(child))) {
 -          author.setName(child.getTextContent());
 -        } else if (Constants.ATOM_ELEM_AUTHOR_URI.equals(XMLUtils.getSimpleName(child)))
{
 -          author.setUri(child.getTextContent());
 -        } else if (Constants.ATOM_ELEM_AUTHOR_EMAIL.equals(XMLUtils.getSimpleName(child)))
{
 -          author.setEmail(child.getTextContent());
 -        }
 -      }
 -      if (!author.isEmpty()) {
 -        entry.setAuthor(author);
 +      if (event.isEndElement() && start.getName().equals(event.asEndElement().getName()))
{
 +        foundEndProperties = true;
        }
      }
 +  }
  
 -    final List<Element> actions = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_ACTION);
 -    for (Element action : actions) {
 -      final ODataOperation operation = new ODataOperation();
 -      operation.setMetadataAnchor(action.getAttribute(Constants.ATTR_METADATA));
 -      operation.setTitle(action.getAttribute(Constants.ATTR_TITLE));
 -      operation.setTarget(URI.create(action.getAttribute(Constants.ATTR_TARGET)));
 +  private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws
XMLStreamException {
 +    if (!Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
 +      return null;
 +    }
  
 -      entry.getOperations().add(operation);
 +    final AtomEntryImpl entry = new AtomEntryImpl();
 +    final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
 +    if (xmlBase != null) {
 +      entry.setBaseURI(xmlBase.getValue());
 +    }
 +    final Attribute etag = start.getAttributeByName(etagQName);
 +    if (etag != null) {
 +      entry.setETag(etag.getValue());
      }
  
 -    final List<Element> contents = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_CONTENT);
 -    if (!contents.isEmpty()) {
 -      final Element content = contents.get(0);
 +    boolean foundEndEntry = false;
 +    while (reader.hasNext() && !foundEndEntry) {
 +      final XMLEvent event = reader.nextEvent();
 +
 +      if (event.isStartElement()) {
 +        if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) {
 +          common(reader, event.asStartElement(), entry, "id");
 +        } else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName()))
{
 +          common(reader, event.asStartElement(), entry, "title");
 +        } else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName()))
{
 +          common(reader, event.asStartElement(), entry, "summary");
 +        } else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName()))
{
 +          common(reader, event.asStartElement(), entry, "updated");
 +        } else if (Constants.QNAME_ATOM_ELEM_CATEGORY.equals(event.asStartElement().getName()))
{
 +          final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM));
 +          if (term != null) {
 +            entry.setType(term.getValue());
 +          }
 +        } else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName()))
{
 +          final LinkImpl link = new LinkImpl();
 +          final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
 +          if (rel != null) {
 +            link.setRel(rel.getValue());
 +          }
 +          final Attribute title = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TITLE));
 +          if (title != null) {
 +            link.setTitle(title.getValue());
 +          }
 +          final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF));
 +          if (href != null) {
 +            link.setHref(href.getValue());
 +          }
 +          final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
 +          if (type != null) {
 +            link.setType(type.getValue());
 +          }
  
 -      List<Element> props = XMLUtils.getChildElements(content, Constants.ELEM_PROPERTIES);
 -      if (props.isEmpty()) {
 -        entry.setMediaContentSource(content.getAttribute(Constants.ATOM_ATTR_SRC));
 -        entry.setMediaContentType(content.getAttribute(Constants.ATTR_TYPE));
 +          if (Constants.SELF_LINK_REL.equals(link.getRel())) {
 +            entry.setSelfLink(link);
 +          } else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
 +            entry.setEditLink(link);
 +          } else if (link.getRel().startsWith(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL)))
{
 +            entry.getNavigationLinks().add(link);
 +            inline(reader, event.asStartElement(), link);
 +          } else if (link.getRel().startsWith(
 +                  version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL)))
{
 +
 +            entry.getAssociationLinks().add(link);
 +          } else if (link.getRel().startsWith(
 +                  version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL)))
{
 +
 +            final Attribute metag = event.asStartElement().getAttributeByName(etagQName);
 +            if (metag != null) {
 +              link.setMediaETag(metag.getValue());
 +            }
 +            entry.getMediaEditLinks().add(link);
 +          }
 +        } else if (actionQName.equals(event.asStartElement().getName())) {
 +          final ODataOperation operation = new ODataOperation();
 +          final Attribute metadata = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_METADATA));
 +          if (metadata != null) {
 +            operation.setMetadataAnchor(metadata.getValue());
 +          }
 +          final Attribute title = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TITLE));
 +          if (title != null) {
 +            operation.setTitle(title.getValue());
 +          }
 +          final Attribute target = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TARGET));
 +          if (target != null) {
 +            operation.setTarget(URI.create(target.getValue()));
 +          }
  
 -        props = XMLUtils.getChildElements(input, Constants.ELEM_PROPERTIES);
 -        if (!props.isEmpty()) {
 -          entry.setMediaEntryProperties(props.get(0));
 +          entry.getOperations().add(operation);
 +        } else if (Constants.QNAME_ATOM_ELEM_CONTENT.equals(event.asStartElement().getName()))
{
 +          final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
 +          if (type == null || ContentType.APPLICATION_XML.getMimeType().equals(type.getValue()))
{
 +            properties(reader, skipBeforeFirstStartElement(reader), entry);
 +          } else {
 +            entry.setMediaContentType(type.getValue());
 +            final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC));
 +            if (src != null) {
 +              entry.setMediaContentSource(src.getValue());
 +            }
 +          }
 +        } else if (propertiesQName.equals(event.asStartElement().getName())) {
 +          properties(reader, event.asStartElement(), entry);
          }
 -      } else {
 -        entry.setContent(props.get(0));
 +      }
 +
 +      if (event.isEndElement() && start.getName().equals(event.asEndElement().getName()))
{
 +        foundEndEntry = true;
        }
      }
  
@@@ -319,21 -215,4 +347,23 @@@
  
      return feed;
    }
 +
 +  private AtomFeedImpl feed(final InputStream input) throws XMLStreamException {
 +    final XMLEventReader reader = FACTORY.createXMLEventReader(input);
 +    return feed(reader, skipBeforeFirstStartElement(reader));
 +  }
 +
 +  @SuppressWarnings("unchecked")
 +  public <T> T read(final InputStream input, final Class<T> reference) throws
XMLStreamException {
 +    if (AtomFeedImpl.class.equals(reference)) {
 +      return (T) feed(input);
 +    } else if (AtomEntryImpl.class.equals(reference)) {
 +      return (T) entry(input);
 +    } else if (AtomPropertyImpl.class.equals(reference)) {
 +      return (T) property(input);
++    } else if (XMLLinkCollectionImpl.class.equals(reference)) {
++      return (T) linkCollection(input);
 +    }
 +    return null;
 +  }
  }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
index 3b66c60,7a358dc..8337a72
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
@@@ -206,56 -176,9 +206,59 @@@ public class AtomSerializer extends Abs
      }
  
      for (Entry entry : feed.getEntries()) {
 -      feedElem.appendChild(doc.importNode(entry((AtomEntryImpl) entry), true));
 +      writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
 +      entry(writer, entry);
 +      writer.writeEndElement();
 +    }
 +
 +    if (feed.getNext() != null) {
 +      final LinkImpl next = new LinkImpl();
 +      next.setRel(Constants.NEXT_LINK_REL);
 +      next.setHref(feed.getNext().toASCIIString());
 +
 +      links(writer, Collections.<Link>singletonList(next));
      }
 +  }
 +
 +  private void feed(final Writer outWriter, final Feed feed) throws XMLStreamException {
 +    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
  
 -    return feedElem;
 +    startDocument(writer, Constants.ATOM_ELEM_FEED);
 +
 +    feed(writer, feed);
 +
 +    writer.writeEndElement();
 +    writer.writeEndDocument();
 +    writer.flush();
 +  }
 +
 +  private void link(final Writer outWriter, final Link link) throws XMLStreamException {
 +    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
 +
 +    writer.writeStartDocument();
-     writer.writeNamespace(
-             Constants.PREFIX_DATASERVICES, version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
 +
-     writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.ELEM_URI);
++    writer.writeStartElement(Constants.ELEM_LINKS);
++    writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
++
++    writer.writeStartElement(Constants.ELEM_URI);
 +    writer.writeCharacters(link.getHref());
 +    writer.writeEndElement();
 +
++    writer.writeEndElement();
++
 +    writer.writeEndDocument();
 +    writer.flush();
 +  }
 +
 +  public <T> void write(final Writer writer, final T obj) throws XMLStreamException
{
 +    if (obj instanceof Feed) {
 +      feed(writer, (Feed) obj);
 +    } else if (obj instanceof Entry) {
 +      entry(writer, (Entry) obj);
 +    } else if (obj instanceof Property) {
 +      property(writer, (Property) obj);
 +    } else if (obj instanceof Link) {
 +      link(writer, (Link) obj);
 +    }
    }
  }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntrySerializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntrySerializer.java
index c6a7b27,36d0d84..2e48f73
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntrySerializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntrySerializer.java
@@@ -26,10 -26,9 +26,11 @@@ import java.util.ArrayList
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
+ import org.apache.commons.lang3.StringUtils;
  import org.apache.olingo.client.api.Constants;
 +import org.apache.olingo.client.api.data.Entry;
  import org.apache.olingo.client.api.data.Link;
 +import org.apache.olingo.client.api.data.Property;
  import org.apache.olingo.client.api.domain.ODataLinkType;
  
  /**
@@@ -53,35 -55,46 +54,37 @@@ public class JSONEntrySerializer extend
      final Map<String, List<String>> entitySetLinks = new HashMap<String,
List<String>>();
  
      for (Link link : entry.getNavigationLinks()) {
 -      if (link.getInlineEntry() != null) {
 -        jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
 -      } else if (link.getInlineFeed() != null) {
 -        jgen.writeObjectField(link.getTitle(), link.getInlineFeed());
 -      } else {
 -        ODataLinkType type = null;
 -        try {
 -          type = ODataLinkType.fromString(client, link.getRel(), link.getType());
 -        } catch (IllegalArgumentException e) {
 -          // ignore   
 -        }
 +      ODataLinkType type = null;
 +      try {
 +        type = ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
 +      } catch (IllegalArgumentException e) {
 +        // ignore   
 +      }
  
 -        if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
 -          final List<String> uris;
 -          if (entitySetLinks.containsKey(link.getTitle())) {
 -            uris = entitySetLinks.get(link.getTitle());
 -          } else {
 -            uris = new ArrayList<String>();
 -            entitySetLinks.put(link.getTitle(), uris);
 -          }
 -          uris.add(link.getHref());
 +      if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
 +        final List<String> uris;
 +        if (entitySetLinks.containsKey(link.getTitle())) {
 +          uris = entitySetLinks.get(link.getTitle());
          } else {
 +          uris = new ArrayList<String>();
 +          entitySetLinks.put(link.getTitle(), uris);
 +        }
 +        uris.add(link.getHref());
 +      } else {
-         jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
++        if (StringUtils.isNotBlank(link.getHref())) {
+           jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
+         }
        }
 +
 +      if (link.getInlineEntry() != null) {
 +        jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
 +      } else if (link.getInlineFeed() != null) {
 +        jgen.writeArrayFieldStart(link.getTitle());
 +        for (Entry subEntry : link.getInlineFeed().getEntries()) {
 +          jgen.writeObject(subEntry);
 +        }
 +        jgen.writeEndArray();
 +      }
      }
      for (Map.Entry<String, List<String>> entitySetLink : entitySetLinks.entrySet())
{
        jgen.writeArrayFieldStart(entitySetLink.getKey() + Constants.JSON_BIND_LINK_SUFFIX);

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
index 998296b,5800c83..172498a
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
@@@ -21,7 -21,8 +21,6 @@@ package org.apache.olingo.client.core.d
  import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.DeserializationContext;
--import com.fasterxml.jackson.databind.JsonNode;
  import com.fasterxml.jackson.databind.node.ObjectNode;
  import java.io.IOException;
  import java.net.URI;
@@@ -47,36 -57,64 +46,24 @@@ public class JSONPropertyDeserializer e
        tree.remove(Constants.JSON_METADATA);
      }
  
 -    try {
 -      final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
 -      final Document document = builder.newDocument();
 -
 -      Element content = document.createElement(Constants.ELEM_PROPERTY);
 -
 -      if (property.getMetadata() != null) {
 -        final String metadataURI = property.getMetadata().toASCIIString();
 -        final int dashIdx = metadataURI.lastIndexOf('#');
 -        if (dashIdx != -1) {
 -          content.setAttribute(Constants.ATTR_M_TYPE, metadataURI.substring(dashIdx + 1));
 -        }
 -      }
 -
 -      JsonNode subtree = null;
 -      if (tree.has(Constants.JSON_VALUE)) {
 -        if (tree.has(Constants.JSON_TYPE)
 -                && StringUtils.isBlank(content.getAttribute(Constants.ATTR_M_TYPE)))
{
 -
 -          content.setAttribute(Constants.ATTR_M_TYPE, tree.get(Constants.JSON_TYPE).asText());
 -        }
 -
 -        final JsonNode value = tree.get(Constants.JSON_VALUE);
 -        if (value.isValueNode()) {
 -          content.appendChild(document.createTextNode(value.asText()));
 -        } else if (ODataJClientEdmPrimitiveType.isGeospatial(content.getAttribute(Constants.ATTR_M_TYPE)))
{
 -          subtree = tree.objectNode();
 -          ((ObjectNode) subtree).put(Constants.JSON_VALUE, tree.get(Constants.JSON_VALUE));
 -          if (StringUtils.isNotBlank(content.getAttribute(Constants.ATTR_M_TYPE))) {
 -            ((ObjectNode) subtree).put(
 -                    Constants.JSON_VALUE + "@" + Constants.JSON_TYPE,
 -                    content.getAttribute(Constants.ATTR_M_TYPE));
 -          }
 -        } else {
 -          subtree = tree.get(Constants.JSON_VALUE);
 -        }
 -      } else {
 -        subtree = tree;
 +    if (property.getMetadata() != null) {
 +      final String metadataURI = property.getMetadata().toASCIIString();
 +      final int dashIdx = metadataURI.lastIndexOf('#');
 +      if (dashIdx != -1) {
 +        property.setType(metadataURI.substring(dashIdx + 1));
        }
 +    }
  
 -      if (subtree != null) {
 -        JSONDOMTreeUtils.buildSubtree(client, content, subtree);
 -      }
 +    if (tree.has(Constants.JSON_TYPE) && property.getType() == null) {
 +      property.setType(tree.get(Constants.JSON_TYPE).asText());
 +    }
  
 -      final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE);
 -      if (children.size() == 1) {
 -        final Element value = (Element) children.iterator().next();
 -        if (Constants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) {
 -          if (StringUtils.isNotBlank(content.getAttribute(Constants.ATTR_M_TYPE))) {
 -            value.setAttribute(Constants.ATTR_M_TYPE, content.getAttribute(Constants.ATTR_M_TYPE));
 -          }
 -          content = value;
 -        }
 -      }
 +    if (tree.has(Constants.JSON_NULL) && tree.get(Constants.JSON_NULL).asBoolean())
{
 +      property.setValue(new NullValueImpl());
 +    }
  
-     JsonNode subtree = null;
-     if (tree.has(Constants.JSON_VALUE)) {
-       final JsonNode value = tree.get(Constants.JSON_VALUE);
-       if (value.isValueNode()) {
-         property.setValue(new PrimitiveValueImpl(value.asText()));
-       } else {
-         subtree = tree.get(Constants.JSON_VALUE);
-       }
-     } else {
-       subtree = tree;
-     }
- 
-     if (property.getValue() == null && subtree != null) {
-       value(property, subtree);
 -      property.setContent(content);
 -    } catch (ParserConfigurationException e) {
 -      throw new JsonParseException("Cannot build property", parser.getCurrentLocation(),
e);
++    if (property.getValue() == null) {
++      value(property, tree.has(Constants.JSON_VALUE) ? tree.get(Constants.JSON_VALUE) :
tree);
      }
  
      return property;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
index 990a942,edead41..9be7636
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
@@@ -136,7 -154,7 +136,7 @@@ public abstract class AbstractODataBind
        entrySelfLink.setRel(Constants.SELF_LINK_REL);
        entry.setSelfLink(entrySelfLink);
      }
--        // -------------------------------------------------------------
++    // -------------------------------------------------------------
  
      // -------------------------------------------------------------
      // Append navigation links (handling inline entry / feed as well)
@@@ -148,7 -166,7 +148,7 @@@
        entry.getNavigationLinks().add(getLink(link,
                ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
      }
--        // -------------------------------------------------------------
++    // -------------------------------------------------------------
  
      // -------------------------------------------------------------
      // Append edit-media links
@@@ -158,7 -176,7 +158,7 @@@
        entry.getMediaEditLinks().add(getLink(link,
                ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
      }
--        // -------------------------------------------------------------
++    // -------------------------------------------------------------
  
      // -------------------------------------------------------------
      // Append association links

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
index fdbd07d,c3c5fb0..d6c5b10
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
@@@ -18,10 -18,18 +18,8 @@@
   */
  package org.apache.olingo.client.core.op.impl;
  
- import java.io.ByteArrayInputStream;
 -import com.fasterxml.aalto.stax.InputFactoryImpl;
 -import com.fasterxml.aalto.stax.OutputFactoryImpl;
 -import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
 -import com.fasterxml.jackson.dataformat.xml.XmlFactory;
 -import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 -
 -import java.io.IOException;
  import java.io.InputStream;
- import org.apache.commons.io.IOUtils;
 -import java.net.URI;
 -
  import org.apache.olingo.client.api.ODataClient;
 -import org.apache.olingo.client.api.Constants;
  import org.apache.olingo.client.api.data.Entry;
  import org.apache.olingo.client.api.data.Error;
  import org.apache.olingo.client.api.data.Feed;
@@@ -78,8 -84,8 +76,8 @@@ public abstract class AbstractODataDese
    @Override
    public LinkCollection toLinkCollection(final InputStream input, final ODataFormat format)
{
      return format == ODataFormat.XML
-             ? xml(input, XMLLinkCollectionImpl.class)
 -            ? toLinkCollectionFromXML(input)
 -            : toLinkCollectionFromJSON(input);
++            ? atom(input, XMLLinkCollectionImpl.class)
 +            : json(input, JSONLinkCollectionImpl.class);
    }
  
    @Override
@@@ -108,14 -119,65 +106,11 @@@
      }
    }
  
 -  protected Feed toJSONFeed(final InputStream input) {
 +  protected <T> T json(final InputStream input, final Class<T> reference) {
      try {
-       String maz = IOUtils.toString(input);
-       ByteArrayInputStream bais = new ByteArrayInputStream(maz.getBytes());
-     System.out.println("KKKKKKKKKKKKKKKKKK\n" + maz);
-       return getObjectMapper().readValue(bais, reference);
 -      return getObjectMapper().readValue(input, JSONFeedImpl.class);
 -    } catch (IOException e) {
 -      throw new IllegalArgumentException("While deserializing JSON feed", e);
 -    }
 -  }
 -
 -  protected Entry toJSONEntry(final InputStream input) {
 -    try {
 -      return getObjectMapper().readValue(input, JSONEntryImpl.class);
 -    } catch (IOException e) {
 -      throw new IllegalArgumentException("While deserializing JSON entry", e);
 -    }
 -  }
 -
 -  protected Element toPropertyDOMFromXML(final InputStream input) {
 -    return toDOM(input);
 -  }
 -
 -  protected Element toPropertyDOMFromJSON(final InputStream input) {
 -    try {
 -      return getObjectMapper().readValue(input, JSONPropertyImpl.class).getContent();
 -    } catch (IOException e) {
 -      throw new IllegalArgumentException("While deserializing JSON property", e);
 -    }
 -  }
 -
 -  protected XMLLinkCollectionImpl toLinkCollectionFromXML(final InputStream input) {
 -    final Element root = toDOM(input);
 -
 -    final NodeList uris = root.getOwnerDocument().getElementsByTagName(Constants.ELEM_URI);
 -
 -    final NodeList next = root.getElementsByTagName(Constants.NEXT_LINK_REL);
 -    final XMLLinkCollectionImpl linkCollection = next.getLength() > 0
 -            ? new XMLLinkCollectionImpl(URI.create(next.item(0).getTextContent()))
 -            : new XMLLinkCollectionImpl();
 -    for (int i = 0; i < uris.getLength(); i++) {
 -      linkCollection.getLinks().add(URI.create(uris.item(i).getTextContent()));
 -    }
 -
 -    return linkCollection;
 -  }
 -
 -  protected JSONLinkCollectionImpl toLinkCollectionFromJSON(final InputStream input) {
 -    try {
 -      return getObjectMapper().readValue(input, JSONLinkCollectionImpl.class);
 -    } catch (IOException e) {
 -      throw new IllegalArgumentException("While deserializing JSON $links", e);
 -    }
 -  }
 -
 -  protected Error toErrorFromXML(final InputStream input) {
 -    try {
 -      final XmlMapper xmlMapper = new XmlMapper(
 -              new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
 -      return xmlMapper.readValue(input, XMLErrorImpl.class);
++      return getObjectMapper().readValue(input, reference);
      } catch (Exception e) {
 -      throw new IllegalArgumentException("While deserializing XML error", e);
 +      throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
      }
    }
  

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
index 4e3409c,4e3409c..091698c
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
@@@ -214,7 -214,7 +214,7 @@@ public abstract class AbstractTestITCas
  
      entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Information",
              getClient().getPrimitiveValueBuilder().setText(sampleinfo).setType(
--            ODataJClientEdmPrimitiveType.String).build()));
++                    ODataJClientEdmPrimitiveType.String).build()));
  
      return entity;
    }
@@@ -228,12 -228,12 +228,12 @@@
      // add name attribute
      entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
              getClient().getPrimitiveValueBuilder().setText(sampleName).setType(
--            ODataJClientEdmPrimitiveType.String).build()));
++                    ODataJClientEdmPrimitiveType.String).build()));
  
      // add key attribute
      entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
              getClient().getPrimitiveValueBuilder().setText(String.valueOf(id)).setType(
--            ODataJClientEdmPrimitiveType.Int32).build()));
++                    ODataJClientEdmPrimitiveType.Int32).build()));
  
      // add BackupContactInfo attribute (collection)
      final ODataCollectionValue backupContactInfoValue = new ODataCollectionValue(

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/4431a80d/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index e9c4259,e74a19b..5915d5e
--- a/pom.xml
+++ b/pom.xml
@@@ -299,7 -293,7 +299,6 @@@
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.16</version>
            <configuration>
--            <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <encoding>utf-8</encoding>
              <runOrder>alphabetical</runOrder>
            </configuration>


Mime
View raw message