Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonToken


        @Override
            public StackTraceElement deserialize(JsonParser jp, DeserializationContext ctxt)
            throws IOException, JsonProcessingException
        {
            JsonToken t = jp.getCurrentToken();
            // Must get an Object
            if (t == JsonToken.START_OBJECT) {
                String className = "", methodName = "", fileName = "";
                int lineNumber = -1;

                while ((t = jp.nextValue()) != JsonToken.END_OBJECT) {
                    String propName = jp.getCurrentName();
                    if ("className".equals(propName)) {
                        className = jp.getText();
                    } else if ("fileName".equals(propName)) {
                        fileName = jp.getText();
                    } else if ("lineNumber".equals(propName)) {
                        if (t.isNumeric()) {
                            lineNumber = jp.getIntValue();
                        } else {
                            throw JsonMappingException.from(jp, "Non-numeric token ("+t+") for property 'lineNumber'");
                        }
                    } else if ("methodName".equals(propName)) {
View Full Code Here


            Enum<?> key = _enumResolver.findEnum(fieldName);
            if (key == null) {
                throw ctxt.weirdStringException(_enumResolver.getEnumClass(), "value not one of declared Enum instance names");
            }
            // And then the value...
            JsonToken t = jp.nextToken();
            /* note: MUST check for nulls separately: deserializers will
             * not handle them (and maybe fail or return bogus data)
             */
            Object value = (t == JsonToken.VALUE_NULL) ?
                null :  _valueDeserializer.deserialize(jp, ctxt);
View Full Code Here

        }

        final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
        Object[] chunk = buffer.resetAndStart();
        int ix = 0;
        JsonToken t;

        while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
            // Note: must handle null explicitly here; value deserializers won't
            Object value = (t == JsonToken.VALUE_NULL) ? null : _elementDeserializer.deserialize(jp, ctxt);
            if (ix >= chunk.length) {
View Full Code Here

    protected byte[] nextBytes() throws IOException {
        if (!jsonParser.hasCurrentToken()) {
            jsonParser.nextToken();
        }

        final JsonToken token = jsonParser.getCurrentToken();

        if ((depth == 0) && (token == JsonToken.START_OBJECT)) {
            jsonParser.nextToken();
            return nextBytes();
        }
View Full Code Here

        }

        try {
            while (eventQueue.isEmpty() || processAttributes) {
                while (true) {
                    final JsonToken jsonToken = parser.nextToken();
                    final ProcessingInfo pi = processingStack.isEmpty() ? null : processingStack.peek();

                    if (jsonToken == null) {
                        return getCurrentNode();
                    }

                    switch (jsonToken) {
                        case FIELD_NAME:
                            final String fieldName = parser.getCurrentName();

                            if (isAttribute(fieldName)) {
                                // attribute
                                final QName attributeName = getAttributeQName(fieldName);
                                final String attributeValue = getPrimitiveFieldValue(parser.nextToken(), parser.getText());

                                eventQueue.peek().getAttributes().add(new JsonXmlEvent.Attribute(attributeName, attributeValue));
                            } else {
                                processAttributes = false;

                                // child event
                                if ("$".equals(fieldName)) {
                                    // character event
                                    final String value = getPrimitiveFieldValue(parser.nextToken(), parser.getText());
                                    eventQueue.add(new CharactersEvent(value, new StaxLocation(parser.getCurrentLocation())));
                                } else {
                                    // element event
                                    final QName elementName = getElementQName(fieldName);
                                    final JsonLocation currentLocation = parser.getCurrentLocation();

                                    final boolean isRootEmpty = isEmptyElement(fieldName, true);
                                    if (isRootEmpty) {
                                        eventQueue.add(createStartElementEvent(elementName, new StaxLocation(currentLocation)));
                                        eventQueue.add(createEndElementEvent(elementName, new StaxLocation(currentLocation)));
                                        eventQueue.add(new EndDocumentEvent(new StaxLocation(parser.getCurrentLocation())));
                                    } else {
                                        if (!isEmptyArray() && !isEmptyElement(fieldName, false)) {
                                            eventQueue.add(createStartElementEvent(elementName, new StaxLocation(currentLocation)));
                                            processingStack.add(new ProcessingInfo(elementName, false, true));
                                        }
                                        if (!parser.hasMoreTokens()) {
                                            eventQueue.add(new EndDocumentEvent(new StaxLocation(parser.getCurrentLocation())));
                                        }
                                    }

                                    if (eventQueue.isEmpty()) {
                                        continue;
                                    }

                                    return getCurrentNode();
                                }
                            }
                            break;
                        case START_OBJECT:
                            if (pi == null) {
                                eventQueue.add(new StartDocumentEvent(new StaxLocation(0, 0, 0)));
                                return getCurrentNode();
                            }
                            if (pi.isArray && !pi.isFirstElement) {
                                eventQueue.add(createStartElementEvent(pi.name, new StaxLocation(parser.getCurrentLocation())));
                                return getCurrentNode();
                            } else {
                                pi.isFirstElement = false;
                            }
                            break;
                        case END_OBJECT:
                            processAttributes = false;

                            // end tag
                            eventQueue.add(createEndElementEvent(pi.name, new StaxLocation(parser.getCurrentLocation())));
                            if (!pi.isArray) {
                                processingStack.pop();
                            }
                            if (processingStack.isEmpty()) {
                                eventQueue.add(new EndDocumentEvent(new StaxLocation(parser.getCurrentLocation())));

                                // Eat the last '}' and check whether there is another (unexpected) token.
                                final JsonToken nextToken = parser.nextToken();
                                if ((nextToken != null && nextToken != JsonToken.END_OBJECT)
                                        || parser.peek() != null) {
                                    throw new RuntimeException("Unexpected token: " + parser.getText());
                                }
                            }
View Full Code Here

     *
     * @return {@code true} if next tokens signalize an empty array, {@code false} otherwise.
     * @throws IOException if there is a problem reading next {@code JsonToken}.
     */
    private boolean isEmptyArray() throws IOException {
        final JsonToken jsonToken = parser.peek();

        if (jsonToken == JsonToken.START_ARRAY && parser.peekNext() == JsonToken.END_ARRAY) {
            // throw away parser tokens
            parser.poll();
            parser.poll();
View Full Code Here

        return false;
    }

    private boolean isEmptyElement(final String fieldName, boolean checkRoot) throws IOException {
        if (!checkRoot || (fieldName != null && fieldName.equals(rootName))) {
            final JsonToken jsonToken = parser.peek();

            if (jsonToken == JsonToken.VALUE_NULL) {
                parser.poll();
                return true;
            }
View Full Code Here

        public JsonToken nextToken() throws IOException {
            return tokens.isEmpty() ? parser.nextToken() : tokens.poll();
        }

        public JsonToken peekNext() throws IOException {
            final JsonToken jsonToken = parser.nextToken();
            tokens.add(jsonToken);
            return jsonToken;
        }
View Full Code Here

        parser.setFeature(feature, isSet);
    }

    @Override
    public JsonToken nextValue() throws IOException, JsonParseException {
        JsonToken result = nextToken();
        while (!result.isScalarValue()) {
            result = nextToken();
        }
        return result;
    }
View Full Code Here

    public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

      LocalDate res = null;

      JsonToken t = jp.getCurrentToken();

      if (t == JsonToken.VALUE_STRING) {
        try {
          String text = jp.getText().trim();
          res = formatter.parseLocalDate(text);
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.JsonToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.