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

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

Introduction

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

Prototype

public abstract JsonToken getCurrentToken();

Source Link

Document

Accessor to find which token parser currently points to, if any; null will be returned if none.

Usage

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

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

    final AbstractProperty property = ODataServiceVersion.V30 == version
            ? new org.apache.olingo.client.core.edm.xml.v3.PropertyImpl()
            : new org.apache.olingo.client.core.edm.xml.v4.PropertyImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                property.setName(jp.nextTextValue());
            } else if ("Type".equals(jp.getCurrentName())) {
                property.setType(jp.nextTextValue());
            } else if ("Nullable".equals(jp.getCurrentName())) {
                property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("DefaultValue".equals(jp.getCurrentName())) {
                property.setDefaultValue(jp.nextTextValue());
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                final String maxLenght = jp.nextTextValue();
                property.setMaxLength(/*  w w  w . java  2 s . c o  m*/
                        maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
            } else if ("FixedLength".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFixedLength(BooleanUtils.toBoolean(jp.nextTextValue()));
                }
            } else if ("Precision".equals(jp.getCurrentName())) {
                property.setPrecision(Integer.valueOf(jp.nextTextValue()));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                property.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("Unicode".equals(jp.getCurrentName())) {
                property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Collation".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setCollation(jp.nextTextValue());
                }
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    property.setSrid(SRID.valueOf(srid));
                }
            } else if ("ConcurrencyMode".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setConcurrencyMode(ConcurrencyMode.valueOf(jp.nextTextValue()));
                }
            } else if ("StoreGeneratedPattern".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setStoreGeneratedPattern(StoreGeneratedPattern.valueOf(jp.nextTextValue()));
                }
            } else if ("FC_SourcePath".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcSourcePath(jp.nextTextValue());
                }
            } else if ("FC_TargetPath".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcTargetPath(jp.nextTextValue());
                }
            } else if ("FC_ContentKind".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcContentKind(EdmContentKind.valueOf(jp.nextTextValue()));
                }
            } else if ("FC_NsPrefix".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcNSPrefix(jp.nextTextValue());
                }
            } else if ("FC_NsUri".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcNSURI(jp.nextTextValue());
                }
            } else if ("FC_KeepInContent".equals(jp.getCurrentName())) {
                if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
                    ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property)
                            .setFcKeepInContent(BooleanUtils.toBoolean(jp.nextTextValue()));
                }
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((org.apache.olingo.client.core.edm.xml.v4.PropertyImpl) property).getAnnotations()
                        .add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return property;
}

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

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

    final ReturnTypeImpl returnType = new ReturnTypeImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Type".equals(jp.getCurrentName())) {
                returnType.setType(jp.nextTextValue());
            } else if ("Nullable".equals(jp.getCurrentName())) {
                returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                final String maxLenght = jp.nextTextValue();
                returnType.setMaxLength(
                        maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
            } else if ("Precision".equals(jp.getCurrentName())) {
                returnType.setPrecision(Integer.valueOf(jp.nextTextValue()));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                returnType.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    returnType.setSrid(SRID.valueOf(srid));
                }//from w ww  .  ja  va  2s .  c  o  m
            }
        }
    }

    return returnType;
}

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

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

    final TermImpl term = new TermImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                term.setName(jp.nextTextValue());
            } else if ("Type".equals(jp.getCurrentName())) {
                term.setType(jp.nextTextValue());
            } else if ("BaseTerm".equals(jp.getCurrentName())) {
                term.setBaseTerm(jp.nextTextValue());
            } else if ("DefaultValue".equals(jp.getCurrentName())) {
                term.setDefaultValue(jp.nextTextValue());
            } else if ("Nullable".equals(jp.getCurrentName())) {
                term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                final String maxLenght = jp.nextTextValue();
                term.setMaxLength(/* w  w w.  ja  v a2s . c o  m*/
                        maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
            } else if ("Precision".equals(jp.getCurrentName())) {
                term.setPrecision(Integer.valueOf(jp.nextTextValue()));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                term.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    term.setSrid(SRID.valueOf(srid));
                }
            } else if ("AppliesTo".equals(jp.getCurrentName())) {
                term.getAppliesTo().addAll(Arrays.asList(StringUtils.split(jp.nextTextValue())));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                term.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return term;
}

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

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

    final TypeDefinitionImpl typeDefinition = new TypeDefinitionImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                typeDefinition.setName(jp.nextTextValue());
            } else if ("UnderlyingType".equals(jp.getCurrentName())) {
                typeDefinition.setUnderlyingType(jp.nextTextValue());
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                typeDefinition.setMaxLength(jp.nextIntValue(0));
            } else if ("Unicode".equals(jp.getCurrentName())) {
                typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Precision".equals(jp.getCurrentName())) {
                typeDefinition.setPrecision(jp.nextIntValue(0));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                typeDefinition.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    typeDefinition.setSrid(SRID.valueOf(srid));
                }// www .j a  v a 2  s  .c  o m
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                typeDefinition.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return typeDefinition;
}

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

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

    final FunctionImportImpl funcImp = new FunctionImportImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                funcImp.setName(jp.nextTextValue());
            } else if ("ReturnType".equals(jp.getCurrentName())) {
                funcImp.setReturnType(jp.nextTextValue());
            } else if ("EntitySet".equals(jp.getCurrentName())) {
                funcImp.setEntitySet(jp.nextTextValue());
            } else if ("EntitySetPath".equals(jp.getCurrentName())) {
                funcImp.setEntitySetPath(jp.nextTextValue());
            } else if ("IsComposable".equals(jp.getCurrentName())) {
                funcImp.setComposable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsSideEffecting".equals(jp.getCurrentName())) {
                funcImp.setSideEffecting(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsBindable".equals(jp.getCurrentName())) {
                funcImp.setBindable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsAlwaysBindable".equals(jp.getCurrentName())) {
                funcImp.setAlwaysBindable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("HttpMethod".equals(jp.getCurrentName())) {
                funcImp.setHttpMethod(jp.nextTextValue());
            } else if ("Parameter".equals(jp.getCurrentName())) {
                jp.nextToken();/* w ww.  jav  a 2  s  . c  o m*/
                funcImp.getParameters().add(jp.readValueAs(ParameterImpl.class));
            }
        }
    }

    return funcImp;
}

From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java

private void rdfJsonToHandlerInternal(final RDFHandler handler, final ValueFactory vf, final JsonParser jp)
        throws IOException, JsonParseException, RDFParseException, RDFHandlerException {
    if (jp.nextToken() != JsonToken.START_OBJECT) {
        reportFatalError("Expected RDF/JSON document to start with an Object", jp.getCurrentLocation());
    }//from  w ww  .j a v a2s  . c om

    while (jp.nextToken() != JsonToken.END_OBJECT) {
        final String subjStr = jp.getCurrentName();
        Resource subject = null;

        subject = subjStr.startsWith("_:") ? createNode(subjStr.substring(2)) : vf.createIRI(subjStr);
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            reportFatalError("Expected subject value to start with an Object", jp.getCurrentLocation());
        }

        boolean foundPredicate = false;
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            final String predStr = jp.getCurrentName();

            final IRI predicate = vf.createIRI(predStr);
            foundPredicate = true;

            if (jp.nextToken() != JsonToken.START_ARRAY) {
                reportFatalError("Expected predicate value to start with an array", jp.getCurrentLocation());
            }

            boolean foundObject = false;

            while (jp.nextToken() != JsonToken.END_ARRAY) {
                if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
                    reportFatalError("Expected object value to start with an Object: subject=<" + subjStr
                            + "> predicate=<" + predStr + ">", jp.getCurrentLocation());
                }

                String nextValue = null;
                String nextType = null;
                String nextDatatype = null;
                String nextLanguage = null;
                final Set<String> nextContexts = new HashSet<String>(2);

                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    final String fieldName = jp.getCurrentName();
                    if (RDFJSONUtility.VALUE.equals(fieldName)) {
                        if (nextValue != null) {
                            reportError(
                                    "Multiple values found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_VALUES);
                        }

                        jp.nextToken();

                        nextValue = jp.getText();
                    } else if (RDFJSONUtility.TYPE.equals(fieldName)) {
                        if (nextType != null) {
                            reportError(
                                    "Multiple types found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_TYPES);
                        }

                        jp.nextToken();

                        nextType = jp.getText();
                    } else if (RDFJSONUtility.LANG.equals(fieldName)) {
                        if (nextLanguage != null) {
                            reportError(
                                    "Multiple languages found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_LANGUAGES);
                        }

                        jp.nextToken();

                        nextLanguage = jp.getText();
                    } else if (RDFJSONUtility.DATATYPE.equals(fieldName)) {
                        if (nextDatatype != null) {
                            reportError(
                                    "Multiple datatypes found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_DATATYPES);
                        }

                        jp.nextToken();

                        nextDatatype = jp.getText();
                    } else if (RDFJSONUtility.GRAPHS.equals(fieldName)) {
                        if (jp.nextToken() != JsonToken.START_ARRAY) {
                            reportError("Expected graphs to start with an array", jp.getCurrentLocation(),
                                    RDFJSONParserSettings.SUPPORT_GRAPHS_EXTENSION);
                        }

                        while (jp.nextToken() != JsonToken.END_ARRAY) {
                            final String nextGraph = jp.getText();
                            nextContexts.add(nextGraph);
                        }
                    } else {
                        reportError(
                                "Unrecognised JSON field name for object: subject=" + subjStr + " predicate="
                                        + predStr + " fieldname=" + fieldName,
                                jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_UNKNOWN_PROPERTY);
                    }
                }

                Value object = null;

                if (nextType == null) {
                    reportFatalError("No type for object: subject=" + subjStr + " predicate=" + predStr,
                            jp.getCurrentLocation());
                }

                if (nextValue == null) {
                    reportFatalError("No value for object: subject=" + subjStr + " predicate=" + predStr,
                            jp.getCurrentLocation());
                }

                if (RDFJSONUtility.LITERAL.equals(nextType)) {
                    if (nextLanguage != null) {
                        object = this.createLiteral(nextValue, nextLanguage, null, jp.getCurrentLocation());
                    } else if (nextDatatype != null) {
                        object = this.createLiteral(nextValue, null, this.createURI(nextDatatype),
                                jp.getCurrentLocation());
                    } else {
                        object = this.createLiteral(nextValue, null, null, jp.getCurrentLocation());
                    }
                } else if (RDFJSONUtility.BNODE.equals(nextType)) {
                    if (nextLanguage != null) {
                        reportFatalError("Language was attached to a blank node object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    if (nextDatatype != null) {
                        reportFatalError("Datatype was attached to a blank node object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    object = createNode(nextValue.substring(2));
                } else if (RDFJSONUtility.URI.equals(nextType)) {
                    if (nextLanguage != null) {
                        reportFatalError("Language was attached to a uri object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    if (nextDatatype != null) {
                        reportFatalError("Datatype was attached to a uri object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    object = vf.createIRI(nextValue);
                }
                foundObject = true;

                if (!nextContexts.isEmpty()) {
                    for (final String nextContext : nextContexts) {
                        final Resource context;

                        if (nextContext.equals(RDFJSONUtility.NULL)) {
                            context = null;
                        } else if (nextContext.startsWith("_:")) {
                            context = createNode(nextContext.substring(2));
                        } else {
                            context = vf.createIRI(nextContext);
                        }
                        Statement st = vf.createStatement(subject, predicate, object, context);
                        if (handler != null) {
                            handler.handleStatement(st);
                        }
                    }
                } else {
                    Statement st = vf.createStatement(subject, predicate, object);
                    if (handler != null) {
                        handler.handleStatement(st);
                    }
                }

            }
            if (!foundObject) {
                reportFatalError("No object for predicate: subject=" + subjStr + " predicate=" + predStr,
                        jp.getCurrentLocation());
            }
        }

        if (!foundPredicate) {
            reportFatalError("No predicate for object: subject=" + subjStr, jp.getCurrentLocation());
        }
    }
}

From source file:org.openhab.binding.weather.internal.parser.JsonWeatherParser.java

/**
 * Iterates through the JSON structure and collects weather data.
 *//*  w w w  .  j  a va  2s  .c om*/
private void handleToken(JsonParser jp, String property, Weather weather) throws Exception {
    JsonToken token = jp.getCurrentToken();
    String prop = PropertyResolver.add(property, jp.getCurrentName());

    if (token.isStructStart()) {
        boolean isObject = token == JsonToken.START_OBJECT || token == JsonToken.END_OBJECT;

        Weather forecast = !isObject ? weather : startIfForecast(weather, prop);
        while (!jp.nextValue().isStructEnd()) {
            handleToken(jp, prop, forecast);
        }
        if (isObject) {
            endIfForecast(weather, forecast, prop);
        }
    } else {
        try {
            setValue(weather, prop, jp.getValueAsString());
        } catch (Exception ex) {
            logger.error("Error setting property '{}' with value '{}' ({})", prop, jp.getValueAsString(),
                    ex.getMessage());
        }
    }
}

From source file:org.openrdf.rio.rdfjson.RDFJSONParser.java

private void rdfJsonToHandlerInternal(final RDFHandler handler, final ValueFactory vf, final JsonParser jp)
        throws IOException, JsonParseException, RDFParseException, RDFHandlerException {
    if (jp.nextToken() != JsonToken.START_OBJECT) {
        reportFatalError("Expected RDF/JSON document to start with an Object", jp.getCurrentLocation());
    }//w  w  w .  jav  a  2  s  .  c  om

    while (jp.nextToken() != JsonToken.END_OBJECT) {
        final String subjStr = jp.getCurrentName();
        Resource subject = null;

        subject = subjStr.startsWith("_:") ? vf.createBNode(subjStr.substring(2)) : vf.createIRI(subjStr);
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            reportFatalError("Expected subject value to start with an Object", jp.getCurrentLocation());
        }

        boolean foundPredicate = false;
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            final String predStr = jp.getCurrentName();

            final IRI predicate = vf.createIRI(predStr);
            foundPredicate = true;

            if (jp.nextToken() != JsonToken.START_ARRAY) {
                reportFatalError("Expected predicate value to start with an array", jp.getCurrentLocation());
            }

            boolean foundObject = false;

            while (jp.nextToken() != JsonToken.END_ARRAY) {
                if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
                    reportFatalError("Expected object value to start with an Object: subject=<" + subjStr
                            + "> predicate=<" + predStr + ">", jp.getCurrentLocation());
                }

                String nextValue = null;
                String nextType = null;
                String nextDatatype = null;
                String nextLanguage = null;
                final Set<String> nextContexts = new HashSet<String>(2);

                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    final String fieldName = jp.getCurrentName();
                    if (RDFJSONUtility.VALUE.equals(fieldName)) {
                        if (nextValue != null) {
                            reportError(
                                    "Multiple values found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_VALUES);
                        }

                        jp.nextToken();

                        nextValue = jp.getText();
                    } else if (RDFJSONUtility.TYPE.equals(fieldName)) {
                        if (nextType != null) {
                            reportError(
                                    "Multiple types found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_TYPES);
                        }

                        jp.nextToken();

                        nextType = jp.getText();
                    } else if (RDFJSONUtility.LANG.equals(fieldName)) {
                        if (nextLanguage != null) {
                            reportError(
                                    "Multiple languages found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_LANGUAGES);
                        }

                        jp.nextToken();

                        nextLanguage = jp.getText();
                    } else if (RDFJSONUtility.DATATYPE.equals(fieldName)) {
                        if (nextDatatype != null) {
                            reportError(
                                    "Multiple datatypes found for a single object: subject=" + subjStr
                                            + " predicate=" + predStr,
                                    jp.getCurrentLocation(),
                                    RDFJSONParserSettings.FAIL_ON_MULTIPLE_OBJECT_DATATYPES);
                        }

                        jp.nextToken();

                        nextDatatype = jp.getText();
                    } else if (RDFJSONUtility.GRAPHS.equals(fieldName)) {
                        if (jp.nextToken() != JsonToken.START_ARRAY) {
                            reportError("Expected graphs to start with an array", jp.getCurrentLocation(),
                                    RDFJSONParserSettings.SUPPORT_GRAPHS_EXTENSION);
                        }

                        while (jp.nextToken() != JsonToken.END_ARRAY) {
                            final String nextGraph = jp.getText();
                            nextContexts.add(nextGraph);
                        }
                    } else {
                        reportError(
                                "Unrecognised JSON field name for object: subject=" + subjStr + " predicate="
                                        + predStr + " fieldname=" + fieldName,
                                jp.getCurrentLocation(), RDFJSONParserSettings.FAIL_ON_UNKNOWN_PROPERTY);
                    }
                }

                Value object = null;

                if (nextType == null) {
                    reportFatalError("No type for object: subject=" + subjStr + " predicate=" + predStr,
                            jp.getCurrentLocation());
                }

                if (nextValue == null) {
                    reportFatalError("No value for object: subject=" + subjStr + " predicate=" + predStr,
                            jp.getCurrentLocation());
                }

                if (RDFJSONUtility.LITERAL.equals(nextType)) {
                    if (nextLanguage != null) {
                        object = this.createLiteral(nextValue, nextLanguage, null, jp.getCurrentLocation());
                    } else if (nextDatatype != null) {
                        object = this.createLiteral(nextValue, null, this.createURI(nextDatatype),
                                jp.getCurrentLocation());
                    } else {
                        object = this.createLiteral(nextValue, null, null, jp.getCurrentLocation());
                    }
                } else if (RDFJSONUtility.BNODE.equals(nextType)) {
                    if (nextLanguage != null) {
                        reportFatalError("Language was attached to a blank node object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    if (nextDatatype != null) {
                        reportFatalError("Datatype was attached to a blank node object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    object = vf.createBNode(nextValue.substring(2));
                } else if (RDFJSONUtility.URI.equals(nextType)) {
                    if (nextLanguage != null) {
                        reportFatalError("Language was attached to a uri object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    if (nextDatatype != null) {
                        reportFatalError("Datatype was attached to a uri object: subject=" + subjStr
                                + " predicate=" + predStr, jp.getCurrentLocation());
                    }
                    object = vf.createIRI(nextValue);
                }
                foundObject = true;

                if (!nextContexts.isEmpty()) {
                    for (final String nextContext : nextContexts) {
                        final Resource context = nextContext.equals(RDFJSONUtility.NULL) ? null
                                : vf.createIRI(nextContext);
                        Statement st = vf.createStatement(subject, predicate, object, context);
                        if (handler != null) {
                            handler.handleStatement(st);
                        }
                    }
                } else {
                    Statement st = vf.createStatement(subject, predicate, object);
                    if (handler != null) {
                        handler.handleStatement(st);
                    }
                }

            }
            if (!foundObject) {
                reportFatalError("No object for predicate: subject=" + subjStr + " predicate=" + predStr,
                        jp.getCurrentLocation());
            }
        }

        if (!foundPredicate) {
            reportFatalError("No predicate for object: subject=" + subjStr, jp.getCurrentLocation());
        }
    }
}