/** * Extracts double value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Double> doubleValueExtractor() { return ValidatingValueExtractor.<Double>builder() .setExtractor(JsonNode::doubleValue) .setValidator( jsonNode -> jsonNode.isDouble() // Either a long number which allows lossless conversion to float || (jsonNode.isIntegralNumber() && jsonNode.canConvertToLong() && jsonNode.asLong() == (long) (double) jsonNode.asInt()) // Or a decimal number which allows lossless conversion to float || (jsonNode.isFloatingPointNumber() && jsonNode .decimalValue() .equals(BigDecimal.valueOf(jsonNode.doubleValue())))) .build(); }
/** * Extracts float value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Float> floatValueExtractor() { return ValidatingValueExtractor.<Float>builder() .setExtractor(JsonNode::floatValue) .setValidator( jsonNode -> jsonNode.isFloat() // Either floating number which allows lossless conversion to float || (jsonNode.isFloatingPointNumber() && jsonNode.doubleValue() == (double) (float) jsonNode.doubleValue()) // Or an integer number which allows lossless conversion to float || (jsonNode.isIntegralNumber() && jsonNode.canConvertToInt() && jsonNode.asInt() == (int) (float) jsonNode.asInt())) .build(); }
/** * Extracts byte value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Byte> byteValueExtractor() { return ValidatingValueExtractor.<Byte>builder() .setExtractor(jsonNode -> (byte) jsonNode.intValue()) .setValidator( jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToInt() && jsonNode.intValue() >= Byte.MIN_VALUE && jsonNode.intValue() <= Byte.MAX_VALUE) .build(); }
/** * Extracts short value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Short> shortValueExtractor() { return ValidatingValueExtractor.<Short>builder() .setExtractor(jsonNode -> (short) jsonNode.intValue()) .setValidator( jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToInt() && jsonNode.intValue() >= Short.MIN_VALUE && jsonNode.intValue() <= Short.MAX_VALUE) .build(); }
/** * Extracts BigDecimal from the JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<BigDecimal> decimalValueExtractor() { return ValidatingValueExtractor.<BigDecimal>builder() .setExtractor(JsonNode::decimalValue) .setValidator(jsonNode -> jsonNode.isNumber()) .build(); }
/** * Extracts boolean value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Boolean> booleanValueExtractor() { return ValidatingValueExtractor.<Boolean>builder() .setExtractor(JsonNode::booleanValue) .setValidator(JsonNode::isBoolean) .build(); }
/** * Extracts long value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Long> longValueExtractor() { return ValidatingValueExtractor.<Long>builder() .setExtractor(JsonNode::longValue) .setValidator(jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToLong()) .build(); }
/** * Extracts string value from the JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<String> stringValueExtractor() { return ValidatingValueExtractor.<String>builder() .setExtractor(JsonNode::textValue) .setValidator(JsonNode::isTextual) .build(); }
/** * Extracts int value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Integer> intValueExtractor() { return ValidatingValueExtractor.<Integer>builder() .setExtractor(JsonNode::intValue) .setValidator(jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToInt()) .build(); }