Repository: olingo-odata4 Updated Branches: refs/heads/master 7ef2d2de4 -> c8d49029f
[OLINGO-575] Refactored last parts of JSON deserializer Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/c8d49029 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/c8d49029 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/c8d49029 Branch: refs/heads/master Commit: c8d49029f246438f259cb4accb4a035ba7cb0c99 Parents: 7ef2d2d Author: Michael Bolz <[email protected]> Authored: Tue Mar 24 09:32:37 2015 +0100 Committer: Michael Bolz <[email protected]> Committed: Tue Mar 24 09:53:44 2015 +0100 ---------------------------------------------------------------------- .../AbstractDynamicAnnotationExpression.java | 140 ++++++++++++++- .../edm/xml/annotation/ApplyDeserializer.java | 57 ------ .../core/edm/xml/annotation/ApplyImpl.java | 32 +++- .../edm/xml/annotation/CastDeserializer.java | 69 ------- .../core/edm/xml/annotation/CastImpl.java | 43 ++++- .../xml/annotation/CollectionDeserializer.java | 52 ------ .../core/edm/xml/annotation/CollectionImpl.java | 26 ++- ...DynamicAnnotationExpressionDeserializer.java | 179 ------------------- .../edm/xml/annotation/IsOfDeserializer.java | 69 ------- .../core/edm/xml/annotation/IsOfImpl.java | 42 ++++- .../annotation/LabeledElementDeserializer.java | 55 ------ .../edm/xml/annotation/LabeledElementImpl.java | 29 ++- .../edm/xml/annotation/NullDeserializer.java | 51 ------ .../core/edm/xml/annotation/NullImpl.java | 25 ++- .../annotation/PropertyValueDeserializer.java | 57 ------ .../edm/xml/annotation/PropertyValueImpl.java | 31 +++- .../edm/xml/annotation/RecordDeserializer.java | 55 ------ .../core/edm/xml/annotation/RecordImpl.java | 28 ++- .../edm/xml/annotation/UrlRefDeserializer.java | 52 ------ .../core/edm/xml/annotation/UrlRefImpl.java | 26 ++- 20 files changed, 412 insertions(+), 706 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/AbstractDynamicAnnotationExpression.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/AbstractDynamicAnnotationExpression.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/AbstractDynamicAnnotationExpression.java index a8d0bcd..18ffb34 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/AbstractDynamicAnnotationExpression.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/AbstractDynamicAnnotationExpression.java @@ -18,6 +18,14 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonLocation; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.ClassUtils; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationPath; import org.apache.olingo.commons.api.edm.provider.annotation.Apply; import org.apache.olingo.commons.api.edm.provider.annotation.Cast; @@ -39,7 +47,9 @@ import org.apache.olingo.commons.api.edm.provider.annotation.UrlRef; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = DynamicAnnotationExpressionDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = AbstractDynamicAnnotationExpression.DynamicAnnotationExpressionDeserializer.class) public abstract class AbstractDynamicAnnotationExpression extends AbstractAnnotationExpression implements DynamicAnnotationExpression { @@ -215,4 +225,132 @@ public abstract class AbstractDynamicAnnotationExpression public UrlRef asUrlRef() { return isUrlRef() ? (UrlRef) this : null; } + + static class DynamicAnnotationExpressionDeserializer + extends AbstractEdmDeserializer<AbstractDynamicAnnotationExpression> { + + private static final String[] EL_OR_ATTR = { + AnnotationPath.class.getSimpleName(), NavigationPropertyPath.class.getSimpleName(), + Path.class.getSimpleName(), PropertyPath.class.getSimpleName() + }; + + private static final String APPLY = Apply.class.getSimpleName(); + private static final String CAST = Cast.class.getSimpleName(); + private static final String COLLECTION = Collection.class.getSimpleName(); + private static final String IF = If.class.getSimpleName(); + private static final String IS_OF = IsOf.class.getSimpleName(); + private static final String LABELED_ELEMENT = LabeledElement.class.getSimpleName(); + private static final String NULL = Null.class.getSimpleName(); + private static final String RECORD = Record.class.getSimpleName(); + private static final String URL_REF = UrlRef.class.getSimpleName(); + + private AbstractElementOrAttributeExpression getElementOrAttributeExpression(final String simpleClassName) + throws JsonParseException { + + try { + @SuppressWarnings("unchecked") + Class<? extends AbstractElementOrAttributeExpression> elOrAttrClass = + (Class<? extends AbstractElementOrAttributeExpression>) ClassUtils.getClass( + getClass().getPackage().getName() + "." + simpleClassName + "Impl"); + return elOrAttrClass.newInstance(); + } catch (Exception e) { + throw new JsonParseException("Could not instantiate " + simpleClassName, JsonLocation.NA, e); + } + } + + private AbstractAnnotationExpression parseConstOrEnumExpression(final JsonParser jp) throws IOException { + AbstractAnnotationExpression result; + if (isAnnotationConstExprConstruct(jp)) { + result = parseAnnotationConstExprConstruct(jp); + } else { + result = jp.readValueAs(AbstractDynamicAnnotationExpression.class); + } + jp.nextToken(); + + return result; + } + + @Override + protected AbstractDynamicAnnotationExpression doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + + AbstractDynamicAnnotationExpression expression = null; + + if ("Not".equals(jp.getCurrentName())) { + final NotImpl not = new NotImpl(); + + jp.nextToken(); + //Search for field name + while (jp.getCurrentToken() != JsonToken.FIELD_NAME) { + jp.nextToken(); + } + not.setExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + //Search for end object + while (jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals("Not")) { + jp.nextToken(); + } + + expression = not; + } else if (TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName()) != null) { + final TwoParamsOpDynamicAnnotationExpressionImpl dynExprDoubleParamOp = + new TwoParamsOpDynamicAnnotationExpressionImpl(); + dynExprDoubleParamOp.setType(TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName())); + + jp.nextToken(); + //Search for field name + while (jp.getCurrentToken() != JsonToken.FIELD_NAME) { + jp.nextToken(); + } + dynExprDoubleParamOp.setLeftExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + dynExprDoubleParamOp.setRightExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + //Search for expression + while (jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals(dynExprDoubleParamOp + .getType().name())) { + jp.nextToken(); + } + + expression = dynExprDoubleParamOp; + } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) { + final AbstractElementOrAttributeExpression elOrAttr = getElementOrAttributeExpression(jp.getCurrentName()); + elOrAttr.setValue(jp.nextTextValue()); + expression = elOrAttr; + } else if (APPLY.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(ApplyImpl.class); + } else if (CAST.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(CastImpl.class); + } else if (COLLECTION.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(CollectionImpl.class); + } else if (IF.equals(jp.getCurrentName())) { + jp.nextToken(); + jp.nextToken(); + + final IfImpl ifImpl = new IfImpl(); + ifImpl.setGuard(parseConstOrEnumExpression(jp)); + ifImpl.setThen(parseConstOrEnumExpression(jp)); + ifImpl.setElse(parseConstOrEnumExpression(jp)); + + expression = ifImpl; + } else if (IS_OF.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(IsOfImpl.class); + } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(LabeledElementImpl.class); + } else if (NULL.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(NullImpl.class); + } else if (RECORD.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(RecordImpl.class); + } else if (URL_REF.equals(jp.getCurrentName())) { + jp.nextToken(); + expression = jp.readValueAs(UrlRefImpl.class); + } + + return expression; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyDeserializer.java deleted file mode 100644 index 8f8ac86..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyDeserializer.java +++ /dev/null @@ -1,57 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class ApplyDeserializer extends AbstractEdmDeserializer<ApplyImpl> { - - @Override - protected ApplyImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final ApplyImpl apply = new ApplyImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Function".equals(jp.getCurrentName())) { - apply.setFunction(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - apply.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else if (isAnnotationConstExprConstruct(jp)) { - apply.getParameters().add(parseAnnotationConstExprConstruct(jp)); - } else { - apply.getParameters().add(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return apply; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyImpl.java index da0fad3..a2733cc 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ApplyImpl.java @@ -18,15 +18,21 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.Apply; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = ApplyDeserializer.class) +@JsonDeserialize(using = ApplyImpl.ApplyDeserializer.class) public class ApplyImpl extends AbstractAnnotatableDynamicAnnotationExpression implements Apply { private static final long serialVersionUID = 4358398303405059879L; @@ -49,4 +55,28 @@ public class ApplyImpl extends AbstractAnnotatableDynamicAnnotationExpression im return parameters; } + static class ApplyDeserializer extends AbstractEdmDeserializer<ApplyImpl> { + + @Override + protected ApplyImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final ApplyImpl apply = new ApplyImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Function".equals(jp.getCurrentName())) { + apply.setFunction(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + apply.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else if (isAnnotationConstExprConstruct(jp)) { + apply.getParameters().add(parseAnnotationConstExprConstruct(jp)); + } else { + apply.getParameters().add(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + + return apply; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastDeserializer.java deleted file mode 100644 index 87e4c84..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastDeserializer.java +++ /dev/null @@ -1,69 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; -import org.apache.olingo.commons.api.edm.geo.SRID; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class CastDeserializer extends AbstractEdmDeserializer<CastImpl> { - - @Override - protected CastImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final CastImpl cast = new CastImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Type".equals(jp.getCurrentName())) { - cast.setType(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - cast.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else if ("MaxLength".equals(jp.getCurrentName())) { - final String maxLenght = jp.nextTextValue(); - cast.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); - } else if ("Precision".equals(jp.getCurrentName())) { - cast.setPrecision(Integer.valueOf(jp.nextTextValue())); - } else if ("Scale".equals(jp.getCurrentName())) { - final String scale = jp.nextTextValue(); - cast.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); - } else if ("SRID".equals(jp.getCurrentName())) { - final String srid = jp.nextTextValue(); - if (srid != null) { - cast.setSrid(SRID.valueOf(srid)); - } - } else { - cast.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return cast; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastImpl.java index 23c86ed..8e8f6e3 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CastImpl.java @@ -18,13 +18,20 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.annotation.Cast; import org.apache.olingo.commons.api.edm.provider.annotation.DynamicAnnotationExpression; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = CastDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = CastImpl.CastDeserializer.class) public class CastImpl extends AbstractAnnotatableDynamicAnnotationExpression implements Cast { private static final long serialVersionUID = 3312415984116005313L; @@ -95,4 +102,38 @@ public class CastImpl extends AbstractAnnotatableDynamicAnnotationExpression imp this.value = value; } + static class CastDeserializer extends AbstractEdmDeserializer<CastImpl> { + + @Override + protected CastImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final CastImpl cast = new CastImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Type".equals(jp.getCurrentName())) { + cast.setType(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + cast.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else if ("MaxLength".equals(jp.getCurrentName())) { + final String maxLenght = jp.nextTextValue(); + cast.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); + } else if ("Precision".equals(jp.getCurrentName())) { + cast.setPrecision(Integer.valueOf(jp.nextTextValue())); + } else if ("Scale".equals(jp.getCurrentName())) { + final String scale = jp.nextTextValue(); + cast.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); + } else if ("SRID".equals(jp.getCurrentName())) { + final String srid = jp.nextTextValue(); + if (srid != null) { + cast.setSrid(SRID.valueOf(srid)); + } + } else { + cast.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + return cast; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionDeserializer.java deleted file mode 100644 index 330c7e0..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionDeserializer.java +++ /dev/null @@ -1,52 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class CollectionDeserializer extends AbstractEdmDeserializer<CollectionImpl> { - - @Override - protected CollectionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final CollectionImpl collection = new CollectionImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if (isAnnotationConstExprConstruct(jp)) { - collection.getItems().add(parseAnnotationConstExprConstruct(jp)); - } else { - collection.getItems().add(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return collection; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionImpl.java index bd48c1a..243d0a3 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/CollectionImpl.java @@ -18,15 +18,20 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.Collection; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = CollectionDeserializer.class) +@JsonDeserialize(using = CollectionImpl.CollectionDeserializer.class) public class CollectionImpl extends AbstractDynamicAnnotationExpression implements Collection { private static final long serialVersionUID = -724749123749715643L; @@ -38,4 +43,23 @@ public class CollectionImpl extends AbstractDynamicAnnotationExpression implemen return items; } + static class CollectionDeserializer extends AbstractEdmDeserializer<CollectionImpl> { + @Override + protected CollectionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final CollectionImpl collection = new CollectionImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if (isAnnotationConstExprConstruct(jp)) { + collection.getItems().add(parseAnnotationConstExprConstruct(jp)); + } else { + collection.getItems().add(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + + return collection; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/DynamicAnnotationExpressionDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/DynamicAnnotationExpressionDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/DynamicAnnotationExpressionDeserializer.java deleted file mode 100644 index 2210a08..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/DynamicAnnotationExpressionDeserializer.java +++ /dev/null @@ -1,179 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.ClassUtils; -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationPath; -import org.apache.olingo.commons.api.edm.provider.annotation.Apply; -import org.apache.olingo.commons.api.edm.provider.annotation.Cast; -import org.apache.olingo.commons.api.edm.provider.annotation.Collection; -import org.apache.olingo.commons.api.edm.provider.annotation.If; -import org.apache.olingo.commons.api.edm.provider.annotation.IsOf; -import org.apache.olingo.commons.api.edm.provider.annotation.LabeledElement; -import org.apache.olingo.commons.api.edm.provider.annotation.NavigationPropertyPath; -import org.apache.olingo.commons.api.edm.provider.annotation.Null; -import org.apache.olingo.commons.api.edm.provider.annotation.Path; -import org.apache.olingo.commons.api.edm.provider.annotation.PropertyPath; -import org.apache.olingo.commons.api.edm.provider.annotation.Record; -import org.apache.olingo.commons.api.edm.provider.annotation.TwoParamsOpDynamicAnnotationExpression; -import org.apache.olingo.commons.api.edm.provider.annotation.UrlRef; - -import com.fasterxml.jackson.core.JsonLocation; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class DynamicAnnotationExpressionDeserializer - extends AbstractEdmDeserializer<AbstractDynamicAnnotationExpression> { - - private static final String[] EL_OR_ATTR = { - AnnotationPath.class.getSimpleName(), NavigationPropertyPath.class.getSimpleName(), - Path.class.getSimpleName(), PropertyPath.class.getSimpleName() - }; - - private static final String APPLY = Apply.class.getSimpleName(); - - private static final String CAST = Cast.class.getSimpleName(); - - private static final String COLLECTION = Collection.class.getSimpleName(); - - private static final String IF = If.class.getSimpleName(); - - private static final String IS_OF = IsOf.class.getSimpleName(); - - private static final String LABELED_ELEMENT = LabeledElement.class.getSimpleName(); - - private static final String NULL = Null.class.getSimpleName(); - - private static final String RECORD = Record.class.getSimpleName(); - - private static final String URL_REF = UrlRef.class.getSimpleName(); - - private AbstractElementOrAttributeExpression getElementOrAttributeExpressio(final String simpleClassName) - throws JsonParseException { - - try { - @SuppressWarnings("unchecked") - Class<? extends AbstractElementOrAttributeExpression> elOrAttrClass = - (Class<? extends AbstractElementOrAttributeExpression>) ClassUtils.getClass( - getClass().getPackage().getName() + "." + simpleClassName + "Impl"); - return elOrAttrClass.newInstance(); - } catch (Exception e) { - throw new JsonParseException("Could not instantiate " + simpleClassName, JsonLocation.NA, e); - } - } - - private AbstractAnnotationExpression parseConstOrEnumExpression(final JsonParser jp) throws IOException { - AbstractAnnotationExpression result; - if (isAnnotationConstExprConstruct(jp)) { - result = parseAnnotationConstExprConstruct(jp); - } else { - result = jp.readValueAs(AbstractDynamicAnnotationExpression.class); - } - jp.nextToken(); - - return result; - } - - @Override - protected AbstractDynamicAnnotationExpression doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - AbstractDynamicAnnotationExpression expression = null; - - if ("Not".equals(jp.getCurrentName())) { - final NotImpl not = new NotImpl(); - - jp.nextToken(); - for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { - //Search for field name - } - not.setExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals("Not"); jp.nextToken()) { - //Search for end object - } - - expression = not; - } else if (TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName()) != null) { - final TwoParamsOpDynamicAnnotationExpressionImpl dynExprDoubleParamOp = - new TwoParamsOpDynamicAnnotationExpressionImpl(); - dynExprDoubleParamOp.setType(TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName())); - - jp.nextToken(); - for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { - //Search for field name - } - dynExprDoubleParamOp.setLeftExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - dynExprDoubleParamOp.setRightExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - for (; jp.getCurrentToken() != JsonToken.END_OBJECT - || !jp.getCurrentName().equals(dynExprDoubleParamOp.getType().name()); jp.nextToken()) { - //Search for expression - } - - expression = dynExprDoubleParamOp; - } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) { - final AbstractElementOrAttributeExpression elOrAttr = getElementOrAttributeExpressio(jp.getCurrentName()); - elOrAttr.setValue(jp.nextTextValue()); - - expression = elOrAttr; - } else if (APPLY.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(ApplyImpl.class); - } else if (CAST.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(CastImpl.class); - } else if (COLLECTION.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(CollectionImpl.class); - } else if (IF.equals(jp.getCurrentName())) { - jp.nextToken(); - jp.nextToken(); - - final IfImpl _if = new IfImpl(); - _if.setGuard(parseConstOrEnumExpression(jp)); - _if.setThen(parseConstOrEnumExpression(jp)); - _if.setElse(parseConstOrEnumExpression(jp)); - - expression = _if; - } else if (IS_OF.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(IsOfImpl.class); - } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(LabeledElementImpl.class); - } else if (NULL.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(NullImpl.class); - } else if (RECORD.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(RecordImpl.class); - } else if (URL_REF.equals(jp.getCurrentName())) { - jp.nextToken(); - expression = jp.readValueAs(UrlRefImpl.class); - } - - return expression; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfDeserializer.java deleted file mode 100644 index 0b1ce80..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfDeserializer.java +++ /dev/null @@ -1,69 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; -import org.apache.olingo.commons.api.edm.geo.SRID; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class IsOfDeserializer extends AbstractEdmDeserializer<IsOfImpl> { - - @Override - protected IsOfImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final IsOfImpl isof = new IsOfImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Type".equals(jp.getCurrentName())) { - isof.setType(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - isof.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else if ("MaxLength".equals(jp.getCurrentName())) { - final String maxLenght = jp.nextTextValue(); - isof.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); - } else if ("Precision".equals(jp.getCurrentName())) { - isof.setPrecision(Integer.valueOf(jp.nextTextValue())); - } else if ("Scale".equals(jp.getCurrentName())) { - final String scale = jp.nextTextValue(); - isof.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); - } else if ("SRID".equals(jp.getCurrentName())) { - final String srid = jp.nextTextValue(); - if (srid != null) { - isof.setSrid(SRID.valueOf(srid)); - } - } else { - isof.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return isof; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfImpl.java index 0eb95de..df5756b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/IsOfImpl.java @@ -18,13 +18,20 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.annotation.DynamicAnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.IsOf; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = IsOfDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = IsOfImpl.IsOfDeserializer.class) public class IsOfImpl extends AbstractAnnotatableDynamicAnnotationExpression implements IsOf { private static final long serialVersionUID = -893355856129761174L; @@ -95,4 +102,37 @@ public class IsOfImpl extends AbstractAnnotatableDynamicAnnotationExpression imp this.value = value; } + static class IsOfDeserializer extends AbstractEdmDeserializer<IsOfImpl> { + @Override + protected IsOfImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final IsOfImpl isof = new IsOfImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Type".equals(jp.getCurrentName())) { + isof.setType(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + isof.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else if ("MaxLength".equals(jp.getCurrentName())) { + final String maxLenght = jp.nextTextValue(); + isof.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); + } else if ("Precision".equals(jp.getCurrentName())) { + isof.setPrecision(Integer.valueOf(jp.nextTextValue())); + } else if ("Scale".equals(jp.getCurrentName())) { + final String scale = jp.nextTextValue(); + isof.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale)); + } else if ("SRID".equals(jp.getCurrentName())) { + final String srid = jp.nextTextValue(); + if (srid != null) { + isof.setSrid(SRID.valueOf(srid)); + } + } else { + isof.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + return isof; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementDeserializer.java deleted file mode 100644 index 5c68abd..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementDeserializer.java +++ /dev/null @@ -1,55 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class LabeledElementDeserializer extends AbstractEdmDeserializer<LabeledElementImpl> { - - @Override - protected LabeledElementImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final LabeledElementImpl element = new LabeledElementImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Name".equals(jp.getCurrentName())) { - element.setName(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - element.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else { - element.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return element; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementImpl.java index 8b24a4f..8d190ce 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/LabeledElementImpl.java @@ -18,12 +18,19 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.provider.annotation.DynamicAnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.LabeledElement; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = LabeledElementDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = LabeledElementImpl.LabeledElementDeserializer.class) public class LabeledElementImpl extends AbstractAnnotatableDynamicAnnotationExpression implements LabeledElement { @@ -51,4 +58,24 @@ public class LabeledElementImpl this.value = value; } + static class LabeledElementDeserializer extends AbstractEdmDeserializer<LabeledElementImpl> { + @Override + protected LabeledElementImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final LabeledElementImpl element = new LabeledElementImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Name".equals(jp.getCurrentName())) { + element.setName(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + element.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else { + element.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + return element; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullDeserializer.java deleted file mode 100644 index 0364a8b..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullDeserializer.java +++ /dev/null @@ -1,51 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class NullDeserializer extends AbstractEdmDeserializer<NullImpl> { - - @Override - protected NullImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final NullImpl _null = new NullImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Annotation".equals(jp.getCurrentName())) { - _null.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } - } - } - - return _null; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullImpl.java index 0aa5d61..f9030f6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/NullImpl.java @@ -18,13 +18,36 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.provider.annotation.Null; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = NullDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = NullImpl.NullDeserializer.class) public class NullImpl extends AbstractAnnotatableDynamicAnnotationExpression implements Null { private static final long serialVersionUID = -3148516847180393142L; + static class NullDeserializer extends AbstractEdmDeserializer<NullImpl> { + @Override + protected NullImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final NullImpl _null = new NullImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Annotation".equals(jp.getCurrentName())) { + _null.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } + } + } + return _null; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueDeserializer.java deleted file mode 100644 index 6c3d151..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueDeserializer.java +++ /dev/null @@ -1,57 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class PropertyValueDeserializer extends AbstractEdmDeserializer<PropertyValueImpl> { - - @Override - protected PropertyValueImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final PropertyValueImpl propValue = new PropertyValueImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Property".equals(jp.getCurrentName())) { - propValue.setProperty(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - propValue.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else if (isAnnotationConstExprConstruct(jp)) { - propValue.setValue(parseAnnotationConstExprConstruct(jp)); - } else { - propValue.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return propValue; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueImpl.java index 5f36ec8..9df0413 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/PropertyValueImpl.java @@ -18,12 +18,19 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.PropertyValue; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = PropertyValueDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = PropertyValueImpl.PropertyValueDeserializer.class) public class PropertyValueImpl extends AbstractAnnotatableDynamicAnnotationExpression implements PropertyValue { private static final long serialVersionUID = -8437649215282645228L; @@ -50,4 +57,26 @@ public class PropertyValueImpl extends AbstractAnnotatableDynamicAnnotationExpre this.value = value; } + static class PropertyValueDeserializer extends AbstractEdmDeserializer<PropertyValueImpl> { + @Override + protected PropertyValueImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final PropertyValueImpl propValue = new PropertyValueImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Property".equals(jp.getCurrentName())) { + propValue.setProperty(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + propValue.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else if (isAnnotationConstExprConstruct(jp)) { + propValue.setValue(parseAnnotationConstExprConstruct(jp)); + } else { + propValue.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + return propValue; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordDeserializer.java deleted file mode 100644 index d680248..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordDeserializer.java +++ /dev/null @@ -1,55 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; -import org.apache.olingo.client.core.edm.xml.AnnotationImpl; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class RecordDeserializer extends AbstractEdmDeserializer<RecordImpl> { - - @Override - protected RecordImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final RecordImpl record = new RecordImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Type".equals(jp.getCurrentName())) { - record.setType(jp.nextTextValue()); - } else if ("Annotation".equals(jp.getCurrentName())) { - record.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); - } else { - record.getPropertyValues().add(jp.readValueAs(PropertyValueImpl.class)); - } - } - } - - return record; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordImpl.java index bafb185..1f200f1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/RecordImpl.java @@ -18,15 +18,21 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; +import org.apache.olingo.client.core.edm.xml.AnnotationImpl; import org.apache.olingo.commons.api.edm.provider.annotation.PropertyValue; import org.apache.olingo.commons.api.edm.provider.annotation.Record; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = RecordDeserializer.class) +@JsonDeserialize(using = RecordImpl.RecordDeserializer.class) public class RecordImpl extends AbstractAnnotatableDynamicAnnotationExpression implements Record { private static final long serialVersionUID = 4275271751615410709L; @@ -49,4 +55,24 @@ public class RecordImpl extends AbstractAnnotatableDynamicAnnotationExpression i return propertyValues; } + static class RecordDeserializer extends AbstractEdmDeserializer<RecordImpl> { + @Override + protected RecordImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final RecordImpl record = new RecordImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Type".equals(jp.getCurrentName())) { + record.setType(jp.nextTextValue()); + } else if ("Annotation".equals(jp.getCurrentName())) { + record.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); + } else { + record.getPropertyValues().add(jp.readValueAs(PropertyValueImpl.class)); + } + } + } + return record; + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefDeserializer.java deleted file mode 100644 index 1ca1241..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefDeserializer.java +++ /dev/null @@ -1,52 +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.edm.xml.annotation; - -import java.io.IOException; - -import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; - -public class UrlRefDeserializer extends AbstractEdmDeserializer<UrlRefImpl> { - - @Override - protected UrlRefImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final UrlRefImpl urlref = new UrlRefImpl(); - - for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { - final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if (isAnnotationConstExprConstruct(jp)) { - urlref.setValue(parseAnnotationConstExprConstruct(jp)); - } else { - urlref.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); - } - } - } - - return urlref; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8d49029/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefImpl.java index 9ec31b0..4c2ac48 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/UrlRefImpl.java @@ -18,12 +18,18 @@ */ package org.apache.olingo.client.core.edm.xml.annotation; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.apache.olingo.client.core.edm.xml.AbstractEdmDeserializer; import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.UrlRef; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -@JsonDeserialize(using = UrlRefDeserializer.class) +import java.io.IOException; + +@JsonDeserialize(using = UrlRefImpl.UrlRefDeserializer.class) public class UrlRefImpl extends AbstractDynamicAnnotationExpression implements UrlRef { private static final long serialVersionUID = -7693224811739000440L; @@ -39,4 +45,22 @@ public class UrlRefImpl extends AbstractDynamicAnnotationExpression implements U this.value = value; } + static class UrlRefDeserializer extends AbstractEdmDeserializer<UrlRefImpl> { + @Override + protected UrlRefImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException { + final UrlRefImpl urlref = new UrlRefImpl(); + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if (isAnnotationConstExprConstruct(jp)) { + urlref.setValue(parseAnnotationConstExprConstruct(jp)); + } else { + urlref.setValue(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); + } + } + } + return urlref; + } + } }
