private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage, JsonNode rootCause, List<String> reasons) { final JsonNode lineJson = rootCause.path("line"); final Integer line = lineJson.isInt() ? lineJson.asInt() : null; final JsonNode columnJson = rootCause.path("col"); final Integer column = columnJson.isInt() ? columnJson.asInt() : null; final String index = rootCause.path("index").asText(null); return new QueryParsingException(errorMessage.get(), line, column, index, reasons); }
@Nullable private Object valueNode(JsonNode jsonNode) { if (jsonNode.isInt()) { return jsonNode.asInt(); } else if (jsonNode.isLong()) { return jsonNode.asLong(); } else if (jsonNode.isIntegralNumber()) { return jsonNode.asLong(); } else if (jsonNode.isFloatingPointNumber()) { return jsonNode.asDouble(); } else if (jsonNode.isBoolean()) { return jsonNode.asBoolean(); } else if (jsonNode.isNull()) { return null; } else { return jsonNode.asText(); } }
/** * Parse the output from the credentials process. */ private JsonNode parseProcessOutput(String processOutput) { JsonNode credentialsJson = Jackson.jsonNodeOf(processOutput); if (!credentialsJson.isObject()) { throw new IllegalStateException("Process did not return a JSON object."); } JsonNode version = credentialsJson.get("Version"); if (version == null || !version.isInt() || version.asInt() != 1) { throw new IllegalStateException("Unsupported credential version: " + version); } return credentialsJson; }
private Object parseId(JsonNode node) { if (isNullNodeOrValue(node)) { return null; } if (node.isDouble()) { return node.asDouble(); } if (node.isFloatingPointNumber()) { return node.asDouble(); } if (node.isInt()) { return node.asInt(); } if (node.isLong()) { return node.asLong(); } //TODO(donequis): consider parsing bigints if (node.isIntegralNumber()) { return node.asInt(); } if (node.isTextual()) { return node.asText(); } throw new IllegalArgumentException("Unknown id type"); }
if (val.isInt() || val.isLong()) { return val.asLong();
if (typeNode.isTextual()) { type = symbolToValueType(typeNode.asText()); } else if (typeNode.isInt()) { type = intToValueType(typeNode.asInt()); } else {
@Override public Object getField(String fieldName) { JsonNode fn = jn.get(fieldName); if (fn.isContainerNode()) { AtomicInteger idx = new AtomicInteger(0); List<Field> fields = Lists.newArrayList(fn.fieldNames()) .stream() .map(f -> new Field(f, idx.getAndIncrement())) .collect(Collectors.toList()); return new GenericJsonRecord(fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isInt()) { return fn.asInt(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isDouble()) { return fn.asDouble(); } else { return fn.asText(); } } }
if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null;
@Override public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode pathDetail = jp.readValueAsTree(); if (pathDetail.size() != 3) throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size()); JsonNode from = pathDetail.get(0); JsonNode to = pathDetail.get(1); JsonNode val = pathDetail.get(2); PathDetail pd; if (val.isBoolean()) pd = new PathDetail(val.asBoolean()); else if (val.isLong()) pd = new PathDetail(val.asLong()); else if (val.isInt()) pd = new PathDetail(val.asInt()); else if (val.isDouble()) pd = new PathDetail(val.asDouble()); else if (val.isTextual()) pd = new PathDetail(val.asText()); else throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name()); pd.setFirst(from.asInt()); pd.setLast(to.asInt()); return pd; } }
} else if (jsonNode.isBoolean()) { return jsonNode.asBoolean(); } else if (jsonNode.isInt()) { if (schema == null || schema.getType().equals(Schema.Type.INT)) { return jsonNode.asInt();
} else if (e.isBoolean()) { return e.asBoolean(); } else if (e.isInt()) { return e.asInt(); } else if (e.isLong()) {
} else if (type.equals("fixed")) { // fixed JsonNode sizeNode = schema.get("size"); if (sizeNode == null || !sizeNode.isInt()) throw new SchemaParseException("Invalid or no size: "+schema); result = new FixedSchema(name, doc, sizeNode.intValue());
@Override public int readI32() throws TException { final Class<?> fieldClass = getCurrentFieldClassIfIs(TEnum.class); if (fieldClass != null) { // Enum fields may be set by string, even though they represent integers. getCurrentContext().read(); final JsonNode elem = getCurrentContext().getCurrentChild(); if (elem.isInt()) { return TypedParser.INTEGER.readFromJsonElement(elem); } else if (elem.isTextual()) { // All TEnum are enums @SuppressWarnings({ "unchecked", "rawtypes" }) final TEnum tEnum = (TEnum) Enum.valueOf((Class<Enum>) fieldClass, TypedParser.STRING.readFromJsonElement(elem)); return tEnum.getValue(); } else { throw new TTransportException("invalid value type for enum field: " + elem.getNodeType() + " (" + elem + ')'); } } else { return readNameOrValue(TypedParser.INTEGER); } }
/** * Parse the output from the credentials process. */ private JsonNode parseProcessOutput(String processOutput) { JsonNode credentialsJson = Jackson.jsonNodeOf(processOutput); if (!credentialsJson.isObject()) { throw new IllegalStateException("Process did not return a JSON object."); } JsonNode version = credentialsJson.get("Version"); if (version == null || !version.isInt() || version.asInt() != 1) { throw new IllegalStateException("Unsupported credential version: " + version); } return credentialsJson; }
@Override public IntOrString deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); IntOrString intOrString = new IntOrString(); if (node.isInt()) { intOrString.setIntVal(node.asInt()); } else { intOrString.setStrVal(node.asText()); } return intOrString; }
private Object valueFromJsonNode(String path, JsonNode valueNode) { if (valueNode == null || valueNode.isNull()) { return null; } else if (valueNode.isTextual()) { return valueNode.asText(); } else if (valueNode.isFloatingPointNumber()) { return valueNode.asDouble(); } else if (valueNode.isBoolean()) { return valueNode.asBoolean(); } else if (valueNode.isInt()) { return valueNode.asInt(); } else if (valueNode.isLong()) { return valueNode.asLong(); } else if (valueNode.isObject() || (valueNode.isArray())) { return new JsonLateObjectEvaluator(mapper, valueNode); } throw new PatchException( String.format("Unrecognized valueNode type at path %s and value node %s.", path, valueNode)); } }
} else if (e.isBoolean()) { return e.asBoolean(); } else if (e.isInt()) { return e.asInt(); } else if (e.isLong()) {
private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage, JsonNode rootCause, List<String> reasons) { final JsonNode lineJson = rootCause.path("line"); final Integer line = lineJson.isInt() ? lineJson.asInt() : null; final JsonNode columnJson = rootCause.path("col"); final Integer column = columnJson.isInt() ? columnJson.asInt() : null; final String index = rootCause.path("index").asText(null); return new QueryParsingException(errorMessage.get(), line, column, index, reasons); }
@Override public void configure(Map stormConf, JsonNode paramNode) { JsonNode node = paramNode.get("maxDepth"); if (node != null && node.isInt()) { maxDepth = node.intValue(); } else { maxDepth = -1; LOG.warn("maxDepth parameter not found"); } }