Java Code Examples for com.fasterxml.jackson.core.JsonParser#NumberType

The following examples show how to use com.fasterxml.jackson.core.JsonParser#NumberType . 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: IsJsonNumber.java    From java-hamcrest with Apache License 2.0 6 votes vote down vote up
public static Matcher<JsonNode> jsonNumber(final NumericNode value) {
  final JsonParser.NumberType numberType = value.numberType();
  switch (numberType) {
    case INT:
      return jsonInt(value.asInt());
    case LONG:
      return jsonLong(value.asLong());
    case BIG_INTEGER:
      return jsonBigInteger(value.bigIntegerValue());
    case FLOAT:
      return jsonFloat(value.floatValue());
    case DOUBLE:
      return jsonDouble(value.doubleValue());
    case BIG_DECIMAL:
      return jsonBigDecimal(value.decimalValue());
    default:
      throw new UnsupportedOperationException("Unsupported number type " + numberType);
  }
}
 
Example 2
Source File: JsonXContentParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private NumberType convertNumberType(JsonParser.NumberType numberType) {
    switch (numberType) {
        case INT:
            return NumberType.INT;
        case LONG:
            return NumberType.LONG;
        case FLOAT:
            return NumberType.FLOAT;
        case DOUBLE:
            return NumberType.DOUBLE;
    }
    throw new IllegalStateException("No matching token for number_type [" + numberType + "]");
}
 
Example 3
Source File: DateTimeSchemasTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public JsonNumberFormatVisitor expectNumberFormat(JavaType type) throws JsonMappingException {
    return new JsonNumberFormatVisitor.Base() {
        @Override
        public void numberType(JsonParser.NumberType format) {
            traversedProperties.put(baseName, "NUMBER/"+format.name());
        }
    };
}
 
Example 4
Source File: DateTimeSchemasTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType type) throws JsonMappingException {
    return new JsonIntegerFormatVisitor.Base() {
        @Override
        public void numberType(JsonParser.NumberType format) {
            traversedProperties.put(baseName, "INTEGER/"+format.name());
        }
    };
}
 
Example 5
Source File: XmlXContentParser.java    From elasticsearch-xml with Apache License 2.0 5 votes vote down vote up
private NumberType convertNumberType(JsonParser.NumberType numberType) {
    switch (numberType) {
        case INT:
            return NumberType.INT;
        case LONG:
            return NumberType.LONG;
        case FLOAT:
            return NumberType.FLOAT;
        case DOUBLE:
            return NumberType.DOUBLE;
    }
    throw new IllegalStateException("No matching token for number_type [" + numberType + "]");
}
 
Example 6
Source File: JsonXContentParser.java    From crate with Apache License 2.0 5 votes vote down vote up
private NumberType convertNumberType(JsonParser.NumberType numberType) {
    switch (numberType) {
        case INT:
            return NumberType.INT;
        case LONG:
            return NumberType.LONG;
        case FLOAT:
            return NumberType.FLOAT;
        case DOUBLE:
            return NumberType.DOUBLE;
        default:
            throw new IllegalStateException("No matching token for number_type [" + numberType + "]");
    }
}
 
Example 7
Source File: JsonIntegerFormatVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void numberType(JsonParser.NumberType type) { }
 
Example 8
Source File: JsonNumberFormatVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void numberType(JsonParser.NumberType type) { }
 
Example 9
Source File: NumericNode.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public abstract JsonParser.NumberType numberType();
 
Example 10
Source File: TreeNodeLazyWrapper.java    From mybatis-jackson with MIT License 4 votes vote down vote up
@Override
public JsonParser.NumberType numberType() {
    return tree().numberType();
}
 
Example 11
Source File: JrsNumber.java    From jackson-jr with Apache License 2.0 4 votes vote down vote up
@Override
public JsonParser.NumberType numberType() {
    return _numberType;
}
 
Example 12
Source File: JsonIntegerFormatVisitor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method called to provide more exact type of number being serialized
 * (regardless of logical type, which may be {@link java.util.Date} or
 * {@link java.lang.Enum}, in addition to actual numeric types like
 * {@link java.lang.Integer}).
 */
public void numberType(JsonParser.NumberType type);
 
Example 13
Source File: JsonNumberFormatVisitor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method called to provide more exact type of number being serialized
 * (regardless of logical type, which may be {@link java.util.Date} or
 * {@link java.lang.Enum}, in addition to actual numeric types like
 * {@link java.lang.Integer}).
 */
public void numberType(JsonParser.NumberType type);