private static <T extends JsonNode> T tryDecode(JsonNode encodedNode, T defaultValue, String fieldName) throws IOException { if (encodedNode == null || encodedNode.isNull()) { return defaultValue; } if (!encodedNode.isTextual()) { throw new IllegalArgumentException("error before decoding " + fieldName + "." + " Expected textual or null field, but encountered " + encodedNode.getNodeType()); } JsonNode decodedNode = mapper.readTree(encodedNode.textValue()); if (!decodedNode.getNodeType().equals(defaultValue.getNodeType())) { throw new IllegalArgumentException("error after decoding" + fieldName + "." + " Expected decoded type to be " + defaultValue.getNodeType() + ", but encountered " + decodedNode.getNodeType()); } return (T) decodedNode; }
public List<String> getTagsStrings(ArrayNode nodes, String location, ParseResult result) { if (nodes == null) return null; List<String> tags = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.STRING)) { tags.add(node.textValue()); } } return tags; }
public List<String> tagStrings(ArrayNode nodes, String location, ParseResult result) { if(nodes == null) return null; List<String> output = new ArrayList<String>(); for(JsonNode node : nodes) { if(node.getNodeType().equals(JsonNodeType.STRING)) { output.add(node.textValue()); } } return output; }
public List<String> getTagsStrings(ArrayNode nodes, String location, ParseResult result) { if (nodes == null) return null; List<String> tags = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.STRING)) { tags.add(node.textValue()); } } return tags; }
public List<String> getTagsStrings(ArrayNode nodes, String location, ParseResult result) { if (nodes == null) return null; List<String> tags = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.STRING)) { tags.add(node.textValue()); } } return tags; }
private List<JsonNode> getPublicEndpoints(JsonNode objectNode) { return objectNode.get("publicEndpoints").getNodeType().equals(JsonNodeType.ARRAY) ? convertJsonArrayToList((ArrayNode) objectNode.get("publicEndpoints")) : Collections.emptyList(); }
public List<Tag> tags(ArrayNode nodes, String location, ParseResult result) { if(nodes == null) return null; List<Tag> output = new ArrayList<Tag>(); for(JsonNode node : nodes) { if(node.getNodeType().equals(JsonNodeType.OBJECT)) { Tag tag = tag((ObjectNode) node, location + ".tags", result); if(tag != null) { output.add(tag); } } } return output; }
public List<Parameter> getParameterList(ArrayNode obj, String location, ParseResult result) { List<Parameter> parameters = new ArrayList<>(); if (obj == null) { return parameters; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Parameter parameter = getParameter((ObjectNode) item, location, result); if (parameter != null) { parameters.add(parameter); } } } return parameters; }
public List<Example> getExampleList(ArrayNode obj, String location, ParseResult result) { List<Example> examples = new ArrayList<>(); if (obj == null) { return examples; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Example example = getExample((ObjectNode) item, location, result); if (example != null) { examples.add(example); } } } return examples; }
public List<Parameter> getParameterList(ArrayNode obj, String location, ParseResult result) { List<Parameter> parameters = new ArrayList<>(); if (obj == null) { return parameters; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Parameter parameter = getParameter((ObjectNode) item, location, result); if (parameter != null) { parameters.add(parameter); } } } return parameters; }
public List<Parameter> parameters(ArrayNode obj, String location, ParseResult result) { List<Parameter> output = new ArrayList<Parameter>(); if(obj == null) { return output; } for(JsonNode item : obj) { if(item.getNodeType().equals(JsonNodeType.OBJECT)) { Parameter param = parameter((ObjectNode) item, location, result); if(param != null) { output.add(param); } } } return output; }
public List<Example> getExampleList(ArrayNode obj, String location, ParseResult result) { List<Example> examples = new ArrayList<>(); if (obj == null) { return examples; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Example example = getExample((ObjectNode) item, location, result); if (example != null) { examples.add(example); } } } return examples; }
public List<Parameter> getParameterList(ArrayNode obj, String location, ParseResult result) { List<Parameter> parameters = new ArrayList<>(); if (obj == null) { return parameters; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Parameter parameter = getParameter((ObjectNode) item, location, result); if (parameter != null) { parameters.add(parameter); } } } return parameters; }
public List<Example> getExampleList(ArrayNode obj, String location, ParseResult result) { List<Example> examples = new ArrayList<>(); if (obj == null) { return examples; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Example example = getExample((ObjectNode) item, location, result); if (example != null) { examples.add(example); } } } return examples; }
public String getString(JsonNode node, String location, ParseResult result) { String output = null; if(!node.getNodeType().equals(JsonNodeType.STRING)) { result.invalidType(location, "", "string", node); } else { output = ((TextNode) node).asText(); } return output; }
public BigDecimal getBigDecimal(String key, ObjectNode node, boolean required, String location, ParseResult result) { BigDecimal value = null; JsonNode v = node.get(key); if (node == null || v == null) { if (required) { result.missing(location, key); result.invalid(); } } else if(v.getNodeType().equals(JsonNodeType.NUMBER)) { value = new BigDecimal(v.asText()); } else if(!v.isValueNode()) { result.invalidType(location, key, "double", node); } return value; }
public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ArrayNode arrayNode = null; if (value == null) { if (required) { result.missing(location, key); result.invalid(); } } else if (!value.getNodeType().equals(JsonNodeType.ARRAY)) { result.invalidType(location, key, "array", value); } else { arrayNode = (ArrayNode) value; } return arrayNode; }
public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ArrayNode arrayNode = null; if (value == null) { if (required) { result.missing(location, key); result.invalid(); } } else if (!value.getNodeType().equals(JsonNodeType.ARRAY)) { result.invalidType(location, key, "array", value); } else { arrayNode = (ArrayNode) value; } return arrayNode; }
public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ArrayNode arrayNode = null; if (value == null) { if (required) { result.missing(location, key); result.invalid(); } } else if (!value.getNodeType().equals(JsonNodeType.ARRAY)) { result.invalidType(location, key, "array", value); } else { arrayNode = (ArrayNode) value; } return arrayNode; }
public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ArrayNode an = null; if(value == null) { if(required) { result.missing(location, key); result.invalid(); } } else if(!value.getNodeType().equals(JsonNodeType.ARRAY)) { result.invalidType(location, key, "array", value); } else { an = (ArrayNode) value; } return an; }