Search in sources :

Example 1 with NumberType

use of com.fasterxml.jackson.core.JsonParser.NumberType in project platformlayer by platformlayer.

the class JsonMetricDataStream method accept.

@Override
public void accept(MetricDataVisitor visitor) throws IOException {
    while (true) {
        JsonToken token = jsonParser.nextToken();
        if (token == null) {
            break;
        }
        switch(token) {
            case START_OBJECT:
                visitor.startObject();
                break;
            case END_OBJECT:
                visitor.endObject();
                break;
            case VALUE_STRING:
                {
                    String s = jsonParser.getText();
                    visitor.gotValueString(s);
                    break;
                }
            case FIELD_NAME:
                {
                    String key = jsonParser.getText();
                    visitor.gotKey(key);
                    break;
                }
            case START_ARRAY:
                visitor.startArray();
                break;
            case END_ARRAY:
                visitor.endArray();
                break;
            case VALUE_FALSE:
                visitor.gotValueBoolean(false);
                break;
            case VALUE_TRUE:
                visitor.gotValueBoolean(false);
                break;
            case VALUE_NULL:
                visitor.gotValueNull();
                break;
            case VALUE_NUMBER_FLOAT:
            case VALUE_NUMBER_INT:
                {
                    NumberType numberType = jsonParser.getNumberType();
                    switch(numberType) {
                        case BIG_INTEGER:
                        case BIG_DECIMAL:
                            {
                                throw new UnsupportedOperationException("Value too large: " + jsonParser.getBigIntegerValue());
                            }
                        case INT:
                            {
                                int v = jsonParser.getIntValue();
                                visitor.gotValueInt(v);
                                break;
                            }
                        case FLOAT:
                            {
                                float v = jsonParser.getFloatValue();
                                visitor.gotValueFloat(v);
                                break;
                            }
                        case DOUBLE:
                            {
                                double v = jsonParser.getDoubleValue();
                                visitor.gotValueDouble(v);
                                break;
                            }
                        case LONG:
                            {
                                long v = jsonParser.getLongValue();
                                visitor.gotValueLong(v);
                                break;
                            }
                        default:
                            throw new IllegalStateException("Unexpected number type: " + numberType);
                    }
                    break;
                }
            case NOT_AVAILABLE:
            case VALUE_EMBEDDED_OBJECT:
            default:
                throw new IllegalStateException("Unexpected token: " + token);
        }
    }
}
Also used : NumberType(com.fasterxml.jackson.core.JsonParser.NumberType) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 2 with NumberType

use of com.fasterxml.jackson.core.JsonParser.NumberType in project jackson-databind by FasterXML.

the class BeanDeserializerBase method deserializeFromNumber.

public Object deserializeFromNumber(JsonParser p, DeserializationContext ctxt) throws IOException {
    // First things first: id Object Id is used, most likely that's it
    if (_objectIdReader != null) {
        return deserializeFromObjectId(p, ctxt);
    }
    final JsonDeserializer<Object> delegateDeser = _delegateDeserializer();
    NumberType nt = p.getNumberType();
    if (nt == NumberType.INT) {
        if (delegateDeser != null) {
            if (!_valueInstantiator.canCreateFromInt()) {
                Object bean = _valueInstantiator.createUsingDelegate(ctxt, delegateDeser.deserialize(p, ctxt));
                if (_injectables != null) {
                    injectValues(ctxt, bean);
                }
                return bean;
            }
        }
        return _valueInstantiator.createFromInt(ctxt, p.getIntValue());
    }
    if (nt == NumberType.LONG) {
        if (delegateDeser != null) {
            if (!_valueInstantiator.canCreateFromInt()) {
                Object bean = _valueInstantiator.createUsingDelegate(ctxt, delegateDeser.deserialize(p, ctxt));
                if (_injectables != null) {
                    injectValues(ctxt, bean);
                }
                return bean;
            }
        }
        return _valueInstantiator.createFromLong(ctxt, p.getLongValue());
    }
    // actually, could also be BigInteger, so:
    if (delegateDeser != null) {
        Object bean = _valueInstantiator.createUsingDelegate(ctxt, delegateDeser.deserialize(p, ctxt));
        if (_injectables != null) {
            injectValues(ctxt, bean);
        }
        return bean;
    }
    return ctxt.handleMissingInstantiator(handledType(), getValueInstantiator(), p, "no suitable creator method found to deserialize from Number value (%s)", p.getNumberValue());
}
Also used : NumberType(com.fasterxml.jackson.core.JsonParser.NumberType)

Example 3 with NumberType

use of com.fasterxml.jackson.core.JsonParser.NumberType in project jackson-databind by FasterXML.

the class BeanDeserializerBase method deserializeFromDouble.

/**
     * Method called to deserialize POJO value from a JSON floating-point
     * number.
     */
public Object deserializeFromDouble(JsonParser p, DeserializationContext ctxt) throws IOException {
    NumberType t = p.getNumberType();
    // no separate methods for taking float...
    if ((t == NumberType.DOUBLE) || (t == NumberType.FLOAT)) {
        JsonDeserializer<Object> delegateDeser = _delegateDeserializer();
        if (delegateDeser != null) {
            if (!_valueInstantiator.canCreateFromDouble()) {
                Object bean = _valueInstantiator.createUsingDelegate(ctxt, delegateDeser.deserialize(p, ctxt));
                if (_injectables != null) {
                    injectValues(ctxt, bean);
                }
                return bean;
            }
        }
        return _valueInstantiator.createFromDouble(ctxt, p.getDoubleValue());
    }
    // actually, could also be BigDecimal, so:
    JsonDeserializer<Object> delegateDeser = _delegateDeserializer();
    if (delegateDeser != null) {
        return _valueInstantiator.createUsingDelegate(ctxt, delegateDeser.deserialize(p, ctxt));
    }
    return ctxt.handleMissingInstantiator(handledType(), getValueInstantiator(), p, "no suitable creator method found to deserialize from Number value (%s)", p.getNumberValue());
}
Also used : NumberType(com.fasterxml.jackson.core.JsonParser.NumberType)

Aggregations

NumberType (com.fasterxml.jackson.core.JsonParser.NumberType)3 JsonToken (com.fasterxml.jackson.core.JsonToken)1