Java Code Examples for com.fasterxml.jackson.core.io.NumberInput#parseAsInt()

The following examples show how to use com.fasterxml.jackson.core.io.NumberInput#parseAsInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserMinimalBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getValueAsInt(int defaultValue) throws IOException
{
    JsonToken t = _currToken;
    if ((t == JsonToken.VALUE_NUMBER_INT) || (t == JsonToken.VALUE_NUMBER_FLOAT)) {
        return getIntValue();
    }
    if (t != null) {
        switch (t.id()) {
        case ID_STRING:
            String str = getText();
            if (_hasTextualNull(str)) {
                return 0;
            }
            return NumberInput.parseAsInt(str, defaultValue);
        case ID_TRUE:
            return 1;
        case ID_FALSE:
            return 0;
        case ID_NULL:
            return 0;
        case ID_EMBEDDED_OBJECT:
            Object value = getEmbeddedObject();
            if (value instanceof Number) {
                return ((Number) value).intValue();
            }
        }
    }
    return defaultValue;
}
 
Example 2
Source File: ParserMinimalBase.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getValueAsInt(int defaultValue) throws IOException
{
    JsonToken t = _currToken;
    if (t == JsonToken.VALUE_NUMBER_INT) {
        return getIntValue();
    }
    if (t == JsonToken.VALUE_NUMBER_FLOAT) {
        return getIntValue();
    }
    if (t != null) {
        switch (t.id()) {
        case ID_STRING:
            String str = getText();
            if (_hasTextualNull(str)) {
                return 0;
            }
            return NumberInput.parseAsInt(str, defaultValue);
        case ID_TRUE:
            return 1;
        case ID_FALSE:
            return 0;
        case ID_NULL:
            return 0;
        case ID_EMBEDDED_OBJECT:
            Object value = this.getEmbeddedObject();
            if (value instanceof Number) {
                return ((Number) value).intValue();
            }
        }
    }
    return defaultValue;
}
 
Example 3
Source File: TextNode.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int asInt(int defaultValue) {
    return NumberInput.parseAsInt(_value, defaultValue);
}