Example usage for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT

List of usage examples for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT.

Prototype

JsonToken VALUE_NUMBER_FLOAT

To view the source code for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT.

Click Source Link

Document

VALUE_NUMBER_INT is returned when a numeric token other that is not an integer is encountered: that is, a number that does have floating point or exponent marker in it, in addition to one or more digits.

Usage

From source file:com.inversoft.json.ZonedDateTimeDeserializer.java

@Override
public ZonedDateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonToken t = jp.getCurrentToken();/*from   w  w  w  . j  a  v  a  2s  .  co m*/
    long value;
    if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
        value = jp.getLongValue();
    } else if (t == JsonToken.VALUE_STRING) {
        String str = jp.getText().trim();
        if (str.length() == 0) {
            return null;
        }

        try {
            value = Long.parseLong(str);
        } catch (NumberFormatException e) {
            throw ctxt.mappingException(handledType());
        }
    } else {
        throw ctxt.mappingException(handledType());
    }

    return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneOffset.UTC);
}

From source file:org.hbz.oerworldmap.JsonDecoder.java

private void handleValue(final JsonToken currentToken, final String key)
        throws IOException, JsonParseException {
    {// ww  w  .  j  a va2s  .  c  o  m
        if (JsonToken.VALUE_STRING == currentToken || JsonToken.VALUE_NUMBER_INT == currentToken
                || JsonToken.VALUE_NUMBER_FLOAT == currentToken) {
            final String value = this.jsonParser.getText();
            JsonDecoder.LOG.debug("key=" + key + " value=" + value);
            getReceiver().literal(key, value);
        }
    }
}

From source file:dk.dma.navnet.messages.TextMessageReader.java

public double takeDouble() throws IOException {
    if (jp.nextToken() != JsonToken.VALUE_NUMBER_FLOAT) {
        throw new IOException("Expected an integer, but was '" + jp.getText() + "'");
    }/*from www. jav a 2  s .  c o m*/
    return jp.getDoubleValue();
}

From source file:org.lobid.lodmill.JsonDecoder.java

private void handleValue(final JsonToken currentToken, final String key)
        throws IOException, JsonParseException {
    {/*from w w  w  .  ja  v  a  2 s  .  co m*/
        if (JsonToken.VALUE_STRING == currentToken || JsonToken.VALUE_NUMBER_INT == currentToken
                || JsonToken.VALUE_NUMBER_FLOAT == currentToken) {
            final String value = this.jsonParser.getText();
            LOG.debug("key=" + key + " value=" + value);
            getReceiver().literal(key, value);
        }
    }
}

From source file:com.addthis.codec.config.ConfigNodeCursor.java

static JsonToken forConfigValue(ConfigValue configValue) {
    ConfigValueType valueType = configValue.valueType();
    switch (valueType) {
    case NUMBER:/*from   ww  w .jav  a  2  s.c  o  m*/
        if (configValue.unwrapped() instanceof Double) {
            return JsonToken.VALUE_NUMBER_FLOAT;
        } else {
            return JsonToken.VALUE_NUMBER_INT;
        }
    case BOOLEAN:
        if (configValue.unwrapped().equals(Boolean.TRUE)) {
            return JsonToken.VALUE_TRUE;
        } else {
            return JsonToken.VALUE_FALSE;
        }
    case NULL:
        return JsonToken.VALUE_NULL;
    case STRING:
        return JsonToken.VALUE_STRING;
    case OBJECT:
        return JsonToken.START_OBJECT;
    case LIST:
        return JsonToken.START_ARRAY;
    default:
        // not possible unless the set of enums changes on us later
        throw new IllegalArgumentException(valueType.name() + " is not a supported ConfigValueType");
    }
}

From source file:com.cinnober.msgcodec.json.TypeScannerJsonParserTest.java

private void assertNextFloatValue(double exp, JsonParser p) throws IOException {
    assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(exp, p.getDoubleValue(), 1e-4);
}

From source file:org.ojai.beans.jackson.DocumentParser.java

@Override
public JsonToken nextToken() throws IOException, JsonParseException {
    if (tokens.isEmpty() && (_currEventType = r.next()) != null) {
        if (r.inMap() && r.getFieldName() != null && _currEventType != EventType.END_MAP
                && _currEventType != EventType.END_ARRAY) {
            tokens.add(JsonToken.FIELD_NAME);
        }/* w  w w. j  a va  2s . c  o  m*/

        switch (_currEventType) {
        case START_ARRAY:
            tokens.add(JsonToken.START_ARRAY);
            break;
        case END_ARRAY:
            tokens.add(JsonToken.END_ARRAY);
            break;
        case START_MAP:
            tokens.add(JsonToken.START_OBJECT);
            break;
        case END_MAP:
            tokens.add(JsonToken.END_OBJECT);
            break;
        case NULL:
            tokens.add(JsonToken.VALUE_NULL);
            break;
        case STRING:
            tokens.add(JsonToken.VALUE_STRING);
            break;
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
            tokens.add(JsonToken.VALUE_NUMBER_INT);
            break;
        case DECIMAL:
        case DOUBLE:
        case FLOAT:
            tokens.add(JsonToken.VALUE_NUMBER_FLOAT);
            break;
        case BOOLEAN:
            tokens.add(r.getBoolean() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE);
            break;
        case DATE:
        case TIME:
        case TIMESTAMP:
        case INTERVAL:
        case BINARY:
            tokens.add(JsonToken.VALUE_EMBEDDED_OBJECT);
            break;
        }
    }
    _currToken = tokens.isEmpty() ? JsonToken.NOT_AVAILABLE : tokens.remove();
    return _currToken;
}

From source file:cz.cvut.kbss.jsonld.jackson.deserialization.JacksonJsonLdDeserializer.java

private Object parseJsonObject(JsonParser parser) throws IOException {
    Object value = null;//from  w w w . ja v a2s  . c o m
    final JsonToken initialToken = parser.getCurrentToken();
    parser.setCodec(mapper);
    if (initialToken == JsonToken.START_ARRAY) {
        value = parser.readValueAs(new TypeReference<List<?>>() {
        });
    } else if (initialToken == JsonToken.START_OBJECT) {
        value = parser.readValueAs(new TypeReference<Map<?, ?>>() {
        });
    } else if (initialToken == JsonToken.VALUE_STRING) {
        value = parser.readValueAs(String.class);
    } else if (initialToken == JsonToken.VALUE_FALSE || initialToken == JsonToken.VALUE_TRUE) {
        value = parser.readValueAs(Boolean.class);
    } else if (initialToken == JsonToken.VALUE_NUMBER_FLOAT || initialToken == JsonToken.VALUE_NUMBER_INT) {
        value = parser.readValueAs(Number.class);
    } else if (initialToken == JsonToken.VALUE_NULL) {
        value = null;
    }
    return value;
}

From source file:org.mongojack.internal.object.BsonObjectCursor.java

private static JsonToken getToken(Object o) {
    if (o == null) {
        return JsonToken.VALUE_NULL;
    } else if (o instanceof Iterable) {
        return JsonToken.START_ARRAY;
    } else if (o instanceof BSONObject) {
        return JsonToken.START_OBJECT;
    } else if (o instanceof Number) {
        if (o instanceof Double || o instanceof Float || o instanceof BigDecimal) {
            return JsonToken.VALUE_NUMBER_FLOAT;
        } else {//ww w. jav  a2 s . c  o m
            return JsonToken.VALUE_NUMBER_INT;
        }
    } else if (o instanceof Boolean) {
        if ((Boolean) o) {
            return JsonToken.VALUE_TRUE;
        } else {
            return JsonToken.VALUE_FALSE;
        }
    } else if (o instanceof CharSequence) {
        return JsonToken.VALUE_STRING;
    } else if (o instanceof ObjectId) {
        return JsonToken.VALUE_EMBEDDED_OBJECT;
    } else if (o instanceof DBRef) {
        return JsonToken.VALUE_EMBEDDED_OBJECT;
    } else if (o instanceof Date) {
        return JsonToken.VALUE_EMBEDDED_OBJECT;
    } else if (o instanceof byte[]) {
        return JsonToken.VALUE_EMBEDDED_OBJECT;
    } else {
        throw new IllegalStateException("Don't know how to parse type: " + o.getClass());
    }
}

From source file:de.undercouch.bson4jackson.BsonParser.java

@Override
public JsonToken nextToken() throws IOException, JsonParseException {
    Context ctx = _currentContext;
    if (_currToken == null && ctx == null) {
        try {/*  w w  w. j a  v  a  2s .c  o  m*/
            _currToken = handleNewDocument(false);
        } catch (EOFException e) {
            //there is nothing more to read. indicate EOF
            return null;
        }
    } else {
        _tokenPos = _counter.getPosition();
        if (ctx == null) {
            if (_currToken == JsonToken.END_OBJECT) {
                //end of input
                return null;
            }
            throw new JsonParseException("Found element outside the document", getTokenLocation());
        }

        if (ctx.state == State.DONE) {
            //next field
            ctx.reset();
        }

        boolean readValue = true;
        if (ctx.state == State.FIELDNAME) {
            readValue = false;
            while (true) {
                //read field name or end of document
                ctx.type = _in.readByte();
                if (ctx.type == BsonConstants.TYPE_END) {
                    //end of document
                    _currToken = (ctx.array ? JsonToken.END_ARRAY : JsonToken.END_OBJECT);
                    _currentContext = _currentContext.parent;
                } else if (ctx.type == BsonConstants.TYPE_UNDEFINED) {
                    //skip field name and then ignore this token
                    skipCString();
                    continue;
                } else {
                    ctx.state = State.VALUE;
                    _currToken = JsonToken.FIELD_NAME;

                    if (ctx.array) {
                        //immediately read value of array element (discard field name)
                        readValue = true;
                        skipCString();
                        ctx.fieldName = null;
                    } else {
                        //read field name
                        ctx.fieldName = readCString();
                    }
                }
                break;
            }
        }

        if (readValue) {
            //parse element's value
            switch (ctx.type) {
            case BsonConstants.TYPE_DOUBLE:
                ctx.value = _in.readDouble();
                _currToken = JsonToken.VALUE_NUMBER_FLOAT;
                break;

            case BsonConstants.TYPE_STRING:
                ctx.value = readString();
                _currToken = JsonToken.VALUE_STRING;
                break;

            case BsonConstants.TYPE_DOCUMENT:
                _currToken = handleNewDocument(false);
                break;

            case BsonConstants.TYPE_ARRAY:
                _currToken = handleNewDocument(true);
                break;

            case BsonConstants.TYPE_BINARY:
                _currToken = handleBinary();
                break;

            case BsonConstants.TYPE_OBJECTID:
                ctx.value = readObjectId();
                _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
                break;

            case BsonConstants.TYPE_BOOLEAN:
                boolean b = _in.readBoolean();
                ctx.value = b;
                _currToken = (b ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE);
                break;

            case BsonConstants.TYPE_DATETIME:
                ctx.value = new Date(_in.readLong());
                _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
                break;

            case BsonConstants.TYPE_NULL:
                _currToken = JsonToken.VALUE_NULL;
                break;

            case BsonConstants.TYPE_REGEX:
                _currToken = handleRegEx();
                break;

            case BsonConstants.TYPE_DBPOINTER:
                _currToken = handleDBPointer();
                break;

            case BsonConstants.TYPE_JAVASCRIPT:
                ctx.value = new JavaScript(readString());
                _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
                break;

            case BsonConstants.TYPE_SYMBOL:
                ctx.value = readSymbol();
                _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
                break;

            case BsonConstants.TYPE_JAVASCRIPT_WITH_SCOPE:
                _currToken = handleJavascriptWithScope();
                break;

            case BsonConstants.TYPE_INT32:
                ctx.value = _in.readInt();
                _currToken = JsonToken.VALUE_NUMBER_INT;
                break;

            case BsonConstants.TYPE_TIMESTAMP:
                ctx.value = readTimestamp();
                _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
                break;

            case BsonConstants.TYPE_INT64:
                ctx.value = _in.readLong();
                _currToken = JsonToken.VALUE_NUMBER_INT;
                break;

            case BsonConstants.TYPE_MINKEY:
                ctx.value = "MinKey";
                _currToken = JsonToken.VALUE_STRING;
                break;

            case BsonConstants.TYPE_MAXKEY:
                ctx.value = "MaxKey";
                _currToken = JsonToken.VALUE_STRING;
                break;

            default:
                throw new JsonParseException("Unknown element type " + ctx.type, getTokenLocation());
            }
            ctx.state = State.DONE;
        }
    }
    return _currToken;
}