Example usage for com.fasterxml.jackson.core JsonParser getCurrentName

List of usage examples for com.fasterxml.jackson.core JsonParser getCurrentName

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser getCurrentName.

Prototype

public abstract String getCurrentName() throws IOException, JsonParseException;

Source Link

Document

Method that can be called to get the name associated with the current token: for JsonToken#FIELD_NAME s it will be the same as what #getText returns; for field values it will be preceding field name; and for others (array values, root-level values) null.

Usage

From source file:com.zenesis.qx.remote.RequestHandler.java

/**
 * Handles dynamic changes to a qa.data.Array instance without having a complete replacement; expects a 
 * serverId, propertyName, type (one of "add", "remove", "order"), start, end, and optional array of items 
 * @param jp/* w ww  .j a  va 2  s.co  m*/
 * @throws ServletException
 * @throws IOException
 */
protected void cmdEditArray(JsonParser jp) throws ServletException, IOException {
    // Get the basics
    int serverId = getFieldValue(jp, "serverId", Integer.class);
    String propertyName = getFieldValue(jp, "propertyName", String.class);
    String action = getFieldValue(jp, "type", String.class);
    Integer start = null;
    Integer end = null;

    if (!action.equals("replaceAll")) {
        start = getFieldValue(jp, "start", Integer.class);
        end = getFieldValue(jp, "end", Integer.class);
    }

    // Get our info
    Proxied serverObject = getProxied(serverId);
    ProxyType type = ProxyTypeManager.INSTANCE.getProxyType(serverObject.getClass());
    ProxyProperty prop = getProperty(type, propertyName);

    if (prop.getPropertyClass().isMap()) {
        Map items = null;

        // Get the optional array of items
        if (jp.nextToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("items")
                && jp.nextToken() == JsonToken.START_OBJECT) {

            items = readMap(jp, prop.getPropertyClass().getKeyClass(), prop.getPropertyClass().getJavaType());
        }

        // Quick logging
        if (log.isInfoEnabled()) {
            String str = "";
            if (items != null)
                for (Object key : items.keySet()) {
                    if (str.length() > 0)
                        str += ", ";
                    str += String.valueOf(key) + "=" + String.valueOf(items.get(key));
                }
            log.info("edit-array: property=" + prop + ", type=" + action + ", start=" + start + ", end=" + end
                    + str);
        }

        if (action.equals("replaceAll")) {
            Map map = (Map) prop.getValue(serverObject);
            if (map == null) {
                try {
                    map = (Map) prop.getPropertyClass().getCollectionClass().newInstance();
                } catch (Exception e) {
                    throw new IllegalArgumentException(e.getMessage(), e);
                }
                prop.setValue(serverObject, map);
            }
            map.clear();
            map.putAll(items);
        } else
            throw new IllegalArgumentException("Unsupported action in cmdEditArray: " + action);

        // Because collection properties are objects and we change them without the serverObject's
        //   knowledge, we have to make sure we notify other trackers ourselves
        ProxyManager.propertyChanged(serverObject, propertyName, items, null);

        jp.nextToken();
    } else {
        // NOTE: items is an Array!!  But because it may be an array of primitive types, we have
        //   to use java.lang.reflect.Array to access members because we cannot cast arrays of
        //   primitives to Object[]
        Object items = null;

        // Get the optional array of items
        if (jp.nextToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("items")
                && jp.nextToken() == JsonToken.START_ARRAY) {

            items = readArray(jp, prop.getPropertyClass().getJavaType());
        }
        int itemsLength = Array.getLength(items);

        // Quick logging
        if (log.isInfoEnabled()) {
            String str = "";
            if (items != null)
                for (int i = 0; i < itemsLength; i++) {
                    if (str.length() != 0)
                        str += ", ";
                    str += Array.get(items, i);
                }
            log.info("edit-array: property=" + prop + ", type=" + action + ", start=" + start + ", end=" + end
                    + str);
        }

        if (action.equals("replaceAll")) {
            if (prop.getPropertyClass().isCollection()) {
                Collection list = (Collection) prop.getValue(serverObject);
                if (list == null) {
                    try {
                        list = (Collection) prop.getPropertyClass().getCollectionClass().newInstance();
                    } catch (Exception e) {
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                    prop.setValue(serverObject, list);
                }
                list.clear();
                if (items != null)
                    for (int i = 0; i < itemsLength; i++)
                        list.add(Array.get(items, i));

                // Because collection properties are objects and we change them without the serverObject's
                //   knowledge, we have to make sure we notify other trackers ourselves
                ProxyManager.propertyChanged(serverObject, propertyName, list, null);
            } else {
                prop.setValue(serverObject, items);
            }
        } else
            throw new IllegalArgumentException("Unsupported action in cmdEditArray: " + action);

        jp.nextToken();
    }
}

From source file:org.instagram4j.DefaultInstagramClient.java

private <T> Result<T> requestEntity(HttpRequestBase method, Class<T> type, boolean signableRequest)
        throws InstagramException {
    method.getParams().setParameter("http.useragent", "Instagram4j/1.0");

    JsonParser jp = null;
    HttpResponse response = null;/*from  ww w .  java2 s  .  c o  m*/
    ResultMeta meta = null;

    try {
        method.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
        if (signableRequest)
            setEnforceHeader(method);

        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT, 15000);
        client.getParams().setParameter(AllClientPNames.SO_TIMEOUT, 30000);

        if (LOG.isDebugEnabled())
            LOG.debug(String.format("Requesting entity entry point %s, method %s", method.getURI().toString(),
                    method.getMethod()));

        autoThrottle();

        response = client.execute(method);

        jp = createParser(response, method);

        JsonToken tok = jp.nextToken();
        if (tok != JsonToken.START_OBJECT) {
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
                throw createInstagramException("Instagram request failed", method.getURI().toString(), response,
                        null, null);

            throw createInstagramException("Invalid response format from Instagram API",
                    method.getURI().toString(), response, null, null);
        }

        T data = null;

        while (true) {
            tok = jp.nextValue();
            if (tok == JsonToken.START_ARRAY) {
                throw createInstagramException("Unexpected array in entity response " + jp.getCurrentName(),
                        method.getURI().toString(), response, meta, null);
            } else if (tok == JsonToken.START_OBJECT) {
                // Should be "data" or "meta"
                String name = jp.getCurrentName();
                if ("meta".equals(name))
                    meta = jp.readValueAs(ResultMeta.class);
                else if ("data".equals(name)) {
                    if (type != null)
                        data = jp.readValueAs(type);
                    else
                        jp.readValueAs(Map.class); // Consume & ignore
                } else
                    throw createInstagramException("Unexpected field name " + name, method.getURI().toString(),
                            response, meta, null);
            } else
                break;
        }

        if (data == null && meta == null && response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
            throw createInstagramException("Instagram request failed", method.getURI().toString(), response,
                    null, null);

        Result<T> result = new Result<T>(null, meta, data);
        setRateLimits(response, result);

        return result;
    } catch (JsonParseException e) {
        throw createInstagramException("Error parsing response from Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } catch (JsonProcessingException e) {
        throw createInstagramException("Error parsing response from Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } catch (IOException e) {
        throw createInstagramException("Error communicating with Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } finally {
        if (jp != null)
            try {
                jp.close();
            } catch (IOException e) {
            }
        method.releaseConnection();
    }
}

From source file:org.instagram4j.DefaultInstagramClient.java

@SuppressWarnings("unchecked")
private <T> Result<T[]> requestEntities(HttpRequestBase method, Class<T> type) throws InstagramException {
    method.getParams().setParameter("http.useragent", "Instagram4j/1.0");

    JsonParser jp = null;
    HttpResponse response = null;// ww  w. jav  a2s .c  om
    ResultMeta meta = null;

    try {
        method.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
        setEnforceHeader(method);

        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT, 15000);
        client.getParams().setParameter(AllClientPNames.SO_TIMEOUT, 30000);

        if (LOG.isDebugEnabled())
            LOG.debug(String.format("Requesting entities entry point %s, method %s", method.getURI().toString(),
                    method.getMethod()));

        autoThrottle();

        response = client.execute(method);

        jp = createParser(response, method);

        JsonToken tok = jp.nextToken();
        if (tok != JsonToken.START_OBJECT) {
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
                throw createInstagramException("Instagram request failed", method.getURI().toString(), response,
                        null, null);

            throw createInstagramException("Invalid response format from Instagram API",
                    method.getURI().toString(), response, null, null);
        }

        Pagination pagination = null;
        T[] data = null;

        while (true) {
            tok = jp.nextValue();
            if (tok == JsonToken.START_ARRAY) {
                // Should be "data"
                String name = jp.getCurrentName();
                if (!"data".equals(name))
                    throw createInstagramException("Unexpected field name " + name, method.getURI().toString(),
                            response, meta, null);

                List<T> items = new ArrayList<T>();

                tok = jp.nextToken();
                if (tok == JsonToken.START_OBJECT) {
                    if (type != null) {
                        T item;
                        while ((item = jp.readValueAs(type)) != null)
                            items.add(item);
                    } else
                        jp.readValueAs(Map.class); // Consume & ignore
                }

                data = (T[]) Array.newInstance(type, items.size());
                System.arraycopy(items.toArray(), 0, data, 0, items.size());
            } else if (tok == JsonToken.START_OBJECT) {
                // Should be "pagination" or "meta"
                String name = jp.getCurrentName();
                if ("pagination".equals(name))
                    pagination = jp.readValueAs(Pagination.class);
                else if ("meta".equals(name))
                    meta = jp.readValueAs(ResultMeta.class);
                else
                    throw createInstagramException("Unexpected field name " + name, method.getURI().toString(),
                            response, meta, null);
            } else
                break;
        }

        if (data == null && meta == null && response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
            throw createInstagramException("Instagram request failed", method.getURI().toString(), response,
                    null, null);

        Result<T[]> result = new Result<T[]>(pagination, meta, data);
        setRateLimits(response, result);

        return result;
    } catch (JsonParseException e) {
        throw createInstagramException("Error parsing response from Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } catch (JsonProcessingException e) {
        throw createInstagramException("Error parsing response from Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } catch (IOException e) {
        throw createInstagramException("Error communicating with Instagram: " + e.getMessage(),
                method.getURI().toString(), response, meta, e);
    } finally {
        if (jp != null)
            try {
                jp.close();
            } catch (IOException e) {
            }
        method.releaseConnection();
    }
}

From source file:com.zenesis.qx.remote.RequestHandler.java

/**
 * Handles creating a server object to match one created on the client; expects className,
 * clientId, properties// ww w. jav a 2s  .com
 * @param jp
 * @throws ServletException
 * @throws IOException
 */
protected void cmdNewObject(JsonParser jp) throws ServletException, IOException {
    // Get the basics
    String className = getFieldValue(jp, "className", String.class);
    int clientId = getFieldValue(jp, "clientId", Integer.class);

    // Get the class
    Class<? extends Proxied> clazz;
    try {
        clazz = (Class<? extends Proxied>) Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ServletException("Unknown class " + className);
    }
    ProxyType type = ProxyTypeManager.INSTANCE.getProxyType(clazz);

    // Create the instance
    Proxied proxied;
    try {
        proxied = type.newInstance(clazz);
    } catch (InstantiationException e) {
        throw new ServletException("Cannot create class " + className + ": " + e.getMessage(), e);
    } catch (InvocationTargetException e) {
        throw new ServletException("Cannot create class " + className + ": " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new ServletException("Cannot create class " + className + ": " + e.getMessage(), e);
    }

    // Get the server ID
    int serverId = tracker.addClientObject(proxied);

    // Remember the client ID, in case there are subsequent commands which refer to it
    if (clientObjects == null)
        clientObjects = new HashMap<Integer, Proxied>();
    clientObjects.put(clientId, proxied);

    // Tell the client about the new ID - do this before changing properties
    tracker.invalidateCache(proxied);
    tracker.getQueue().queueCommand(CommandId.CommandType.MAP_CLIENT_ID, proxied, null,
            new MapClientId(serverId, clientId));

    // Set property values
    if (jp.nextToken() == JsonToken.FIELD_NAME) {
        if (jp.nextToken() != JsonToken.START_OBJECT)
            throw new ServletException("Unexpected properties definiton for 'new' command");
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            String propertyName = jp.getCurrentName();
            jp.nextToken();

            // Read a Proxied object?  
            ProxyProperty prop = getProperty(type, propertyName);
            MetaClass propClass = prop.getPropertyClass();
            Object value = null;
            if (propClass.isSubclassOf(Proxied.class)) {

                if (propClass.isArray() || propClass.isCollection()) {
                    value = readArray(jp, propClass.getJavaType());

                } else if (propClass.isMap()) {
                    value = readMap(jp, propClass.getKeyClass(), propClass.getJavaType());

                } else {
                    Integer id = jp.readValueAs(Integer.class);
                    if (id != null)
                        value = getProxied(id);
                }
            } else {
                value = jp.readValueAs(Object.class);
                if (value != null && Enum.class.isAssignableFrom(propClass.getJavaType())) {
                    String str = Helpers.camelCaseToEnum(value.toString());
                    value = Enum.valueOf(propClass.getJavaType(), str);
                }
            }
            setPropertyValue(type, proxied, propertyName, value);
        }
    }

    // Done
    jp.nextToken();
}

From source file:org.apache.olingo.client.core.edm.xml.ActionDeserializer.java

@Override
protected ActionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final ActionImpl action = new ActionImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                action.setName(jp.nextTextValue());
            } else if ("IsBound".equals(jp.getCurrentName())) {
                action.setBound(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("EntitySetPath".equals(jp.getCurrentName())) {
                action.setEntitySetPath(jp.nextTextValue());
            } else if ("Parameter".equals(jp.getCurrentName())) {
                jp.nextToken();/*w  ww. j a v  a 2  s. c om*/
                action.getParameters().add(jp.readValueAs(ParameterImpl.class));
            } else if ("ReturnType".equals(jp.getCurrentName())) {
                action.setReturnType(parseReturnType(jp, "Action"));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                action.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return action;
}

From source file:org.apache.olingo.client.core.edm.xml.annotation.DynamicAnnotationExpressionDeserializer.java

@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();//from   w ww. j a v a  2s.c  om
        for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) {
        }
        not.setExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class));
        for (; 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();
        for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) {
        }
        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()) {
        }

        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;
}

From source file:org.apache.olingo.client.core.edm.xml.ComplexTypeDeserializer.java

@Override
protected AbstractComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final AbstractComplexType complexType = ODataServiceVersion.V30 == version
            ? new org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl()
            : new org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                complexType.setName(jp.nextTextValue());
            } else if ("Abstract".equals(jp.getCurrentName())) {
                ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType)
                        .setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("BaseType".equals(jp.getCurrentName())) {
                ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType)
                        .setBaseType(jp.nextTextValue());
            } else if ("OpenType".equals(jp.getCurrentName())) {
                ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType)
                        .setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Property".equals(jp.getCurrentName())) {
                jp.nextToken();//from  www  .ja v  a 2 s.c  o m
                if (complexType instanceof org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) complexType).getProperties()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v3.PropertyImpl.class));
                } else {
                    ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).getProperties()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v4.PropertyImpl.class));
                }
            } else if ("NavigationProperty".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType)
                        .getNavigationProperties().add(jp.readValueAs(
                                org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyImpl.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).getAnnotations()
                        .add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return complexType;
}

From source file:org.apache.olingo.client.core.edm.xml.EntityContainerDeserializer.java

@Override
protected AbstractEntityContainer doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final AbstractEntityContainer entityContainer = ODataServiceVersion.V30 == version
            ? new org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl()
            : new org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                entityContainer.setName(jp.nextTextValue());
            } else if ("Extends".equals(jp.getCurrentName())) {
                entityContainer.setExtends(jp.nextTextValue());
            } else if ("LazyLoadingEnabled".equals(jp.getCurrentName())) {
                entityContainer.setLazyLoadingEnabled(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsDefaultEntityContainer".equals(jp.getCurrentName())) {
                entityContainer.setDefaultEntityContainer(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("EntitySet".equals(jp.getCurrentName())) {
                jp.nextToken();/*w  w  w.ja v a 2 s . c  om*/
                if (entityContainer instanceof org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer)
                            .getEntitySets()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v3.EntitySetImpl.class));
                } else {
                    ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer)
                            .getEntitySets()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl.class));
                }
            } else if ("AssociationSet".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer)
                        .getAssociationSets().add(jp.readValueAs(AssociationSetImpl.class));
            } else if ("Singleton".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).getSingletons()
                        .add(jp.readValueAs(SingletonImpl.class));
            } else if ("ActionImport".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer)
                        .getActionImports().add(jp.readValueAs(ActionImportImpl.class));
            } else if ("FunctionImport".equals(jp.getCurrentName())) {
                jp.nextToken();
                if (entityContainer instanceof org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer)
                            .getFunctionImports().add(jp.readValueAs(
                                    org.apache.olingo.client.core.edm.xml.v3.FunctionImportImpl.class));
                } else {
                    ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer)
                            .getFunctionImports().add(jp.readValueAs(
                                    org.apache.olingo.client.core.edm.xml.v4.FunctionImportImpl.class));
                }
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer)
                        .getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return entityContainer;
}

From source file:org.apache.olingo.client.core.edm.xml.EntitySetDeserializer.java

@Override
protected AbstractEntitySet doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final AbstractEntitySet entitySet = ODataServiceVersion.V30 == version
            ? new org.apache.olingo.client.core.edm.xml.v3.EntitySetImpl()
            : new org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                entitySet.setName(jp.nextTextValue());
            } else if ("EntityType".equals(jp.getCurrentName())) {
                entitySet.setEntityType(jp.nextTextValue());
            } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) {
                ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet)
                        .setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) {
                jp.nextToken();/*from  w ww.j  av a2s  .c  o m*/
                ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet)
                        .getNavigationPropertyBindings()
                        .add(jp.readValueAs(NavigationPropertyBindingImpl.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet).getAnnotations()
                        .add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return entitySet;
}

From source file:org.apache.olingo.client.core.edm.xml.EntityTypeDeserializer.java

@Override
protected AbstractEntityType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final AbstractEntityType entityType = ODataServiceVersion.V30 == version
            ? new org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl()
            : new org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                entityType.setName(jp.nextTextValue());
            } else if ("Abstract".equals(jp.getCurrentName())) {
                entityType.setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("BaseType".equals(jp.getCurrentName())) {
                entityType.setBaseType(jp.nextTextValue());
            } else if ("OpenType".equals(jp.getCurrentName())) {
                entityType.setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("HasStream".equals(jp.getCurrentName())) {
                entityType.setHasStream(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Key".equals(jp.getCurrentName())) {
                jp.nextToken();//from   w ww  .  j  av  a2  s .c om
                entityType.setKey(jp.readValueAs(EntityKeyImpl.class));
            } else if ("Property".equals(jp.getCurrentName())) {
                jp.nextToken();
                if (entityType instanceof org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) entityType).getProperties()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v3.PropertyImpl.class));
                } else {
                    ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType).getProperties()
                            .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v4.PropertyImpl.class));
                }
            } else if ("NavigationProperty".equals(jp.getCurrentName())) {
                jp.nextToken();
                if (entityType instanceof org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) entityType)
                            .getNavigationProperties().add(jp.readValueAs(
                                    org.apache.olingo.client.core.edm.xml.v3.NavigationPropertyImpl.class));
                } else {
                    ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType)
                            .getNavigationProperties().add(jp.readValueAs(
                                    org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyImpl.class));
                }
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType).getAnnotations()
                        .add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return entityType;
}