Refine search
/** * Get a textual value from a json object, throwing an exception if the node is missing or not textual. */ private String getText(JsonNode jsonObject, String nodeName) { JsonNode subNode = jsonObject.get(nodeName); if (subNode == null) { return null; } if (!subNode.isTextual()) { throw new IllegalStateException(nodeName + " from credential process should be textual, but was " + subNode.getNodeType()); } return subNode.asText(); }
private String getTypeName(JsonNode node) { if (node.has("type") && node.get("type").isArray() && node.get("type").size() > 0) { for (JsonNode jsonNode : node.get("type")) { String typeName = jsonNode.asText(); if (!typeName.equals("null")) { return typeName; } } } if (node.has("type") && node.get("type").isTextual()) { return node.get("type").asText(); } return DEFAULT_TYPE_NAME; }
private static void addHeader(DeserializationContext ctx, HttpHeaders headers, AsciiString name, JsonNode valueNode) throws JsonMappingException { if (!valueNode.isTextual()) { ctx.reportInputMismatch(HttpHeaders.class, "HTTP header '%s' contains %s (%s); only strings are allowed.", name, valueNode.getNodeType(), valueNode); } headers.add(name, valueNode.asText()); } }
private AuthConfig authConfigUsingHelper(final JsonNode config, final String reposName) throws Exception { final JsonNode credHelpers = config.get("credHelpers"); if (credHelpers != null && credHelpers.size() > 0) { final JsonNode helperNode = credHelpers.get(reposName); if (helperNode != null && helperNode.isTextual()) { final String helper = helperNode.asText(); return runCredentialProvider(reposName, helper); } } return null; }
public static JsonNode validateIfNodeIsTextual(JsonNode node) { if (node != null && !node.isNull() && node.isTextual() && StringUtils.isNotEmpty(node.asText())) { try { node = validateIfNodeIsTextual(objectMapper.readTree(node.asText())); } catch(Exception e) { logger.error("Error converting textual node", e); } } return node; }
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (node.isTextual()) { return node.textValue(); } else if (node.isObject()) { JsonNode allNode = node.get("__all__"); if (allNode != null && allNode.isArray()) { StringBuilder buf = new StringBuilder(); for (JsonNode msgNode : allNode) { buf.append(msgNode.textValue()); buf.append(","); } return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString(); } return node.toString(); } 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; } }
log.warn(prefix + "is missing mandatory \"host\" field."); } else { if (!hostNode.isTextual()) { throw new IllegalArgumentException(prefix + "has invalid \"host\": " + hostNode.asText()); if (StringUtils.isBlank(hostNode.asText())) { throw new IllegalArgumentException(prefix + "has empty mandatory \"host\" field."); final JsonNode messageNode = jsonNode.path("message"); if (!shortMessageNode.isMissingNode()) { if (!shortMessageNode.isTextual()) { throw new IllegalArgumentException(prefix + "has invalid \"short_message\": " + shortMessageNode.asText()); if (StringUtils.isBlank(shortMessageNode.asText()) && StringUtils.isBlank(messageNode.asText())) { if (!messageNode.isTextual()) { throw new IllegalArgumentException(prefix + "has invalid \"message\": " + messageNode.asText());
List<String> getStringOrArray(Map<String, JsonNode> tree, String claimName) throws JWTDecodeException { JsonNode node = tree.get(claimName); if (node == null || node.isNull() || !(node.isArray() || node.isTextual())) { return null; } if (node.isTextual() && !node.asText().isEmpty()) { return Collections.singletonList(node.asText()); } List<String> list = new ArrayList<>(node.size()); for (int i = 0; i < node.size(); i++) { try { list.add(objectReader.treeToValue(node.get(i), String.class)); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to String", e); } } return list; }
private static double timestampValue(final JsonNode json) { final JsonNode value = json.path(Message.FIELD_TIMESTAMP); if (value.isNumber()) { return value.asDouble(-1.0); } else if (value.isTextual()) { try { return Double.parseDouble(value.asText()); } catch (NumberFormatException e) { log.debug("Unable to parse timestamp", e); return -1.0; } } else { return -1.0; } }
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (node.isTextual()) { return node.textValue(); } else if (node.isObject()) { JsonNode allNode = node.get("__all__"); if (allNode != null && allNode.isArray()) { StringBuilder buf = new StringBuilder(); for (JsonNode msgNode : allNode) { buf.append(msgNode.textValue()); buf.append(","); } return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString(); } return node.toString(); } return null; } }
/** * Get a textual value from a json object, throwing an exception if the node is missing or not textual. */ private String getText(JsonNode jsonObject, String nodeName) { JsonNode subNode = jsonObject.get(nodeName); if (subNode == null) { return null; } if (!subNode.isTextual()) { throw new IllegalStateException(nodeName + " from credential process should be textual, but was " + subNode.getNodeType()); } return subNode.asText(); }
/** * Parse the error message from the response. * * @return Error Code of exceptional response or null if it can't be determined */ public String parseErrorMessage(HttpResponse httpResponse, JsonNode jsonNode) { // If X_AMZN_ERROR_MESSAGE is present, prefer that. Otherwise check the JSON body. final String headerMessage = httpResponse.getHeader(X_AMZN_ERROR_MESSAGE); if (headerMessage != null) { return headerMessage; } for (String field : errorMessageJsonLocations) { JsonNode value = jsonNode.get(field); if (value != null && value.isTextual()) { return value.asText(); } } return null; }
@JsonSetter("channel") public void setChannel(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.channel = new ObjectMapper().treeToValue(jsonNode, Channel.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.channelId = jsonNode.asText(); } }
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (node.isTextual()) { return node.textValue(); } else if (node.isObject()) { JsonNode allNode = node.get("__all__"); if (allNode != null && allNode.isArray()) { StringBuffer buf = new StringBuffer(); for (JsonNode msgNode : allNode) { buf.append(msgNode.textValue()); buf.append(","); } return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString(); } return node.toString(); } return null; } }
private AuthConfig authConfigUsingStore(final JsonNode config, final String reposName) throws Exception { final JsonNode credsStoreNode = config.get("credsStore"); if (credsStoreNode != null && !credsStoreNode.isMissingNode() && credsStoreNode.isTextual()) { final String credsStore = credsStoreNode.asText(); return runCredentialProvider(reposName, credsStore); } return null; }
@JsonSetter("file") public void setFile(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.file = new ObjectMapper().treeToValue(jsonNode, File.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.fileId = jsonNode.asText(); } }
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (node.isTextual()) { return node.textValue(); } else if (node.isObject()) { JsonNode allNode = node.get("__all__"); if (allNode != null && allNode.isArray()) { StringBuffer buf = new StringBuffer(); for (JsonNode msgNode : allNode) { buf.append(msgNode.textValue()); buf.append(","); } return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString(); } return node.toString(); } return null; } }