public static <T> T jsonNodeToObject(JsonNode jsonNode, Class<T> valueType) throws JsonProcessingException { return DEFAULT_READER.treeToValue(jsonNode, valueType); }
@Override @SuppressWarnings("unchecked") public <T> T[] asArray(Class<T> tClazz) throws JWTDecodeException { if (!data.isArray()) { return null; } T[] arr = (T[]) Array.newInstance(tClazz, data.size()); for (int i = 0; i < data.size(); i++) { try { arr[i] = objectReader.treeToValue(data.get(i), tClazz); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e); } } return arr; }
@Override public <T> List<T> asList(Class<T> tClazz) throws JWTDecodeException { if (!data.isArray()) { return null; } List<T> list = new ArrayList<>(); for (int i = 0; i < data.size(); i++) { try { list.add(objectReader.treeToValue(data.get(i), tClazz)); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e); } } return list; }
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; }
/** * @param ipAddress IPv4 or IPv6 address to lookup. * @return An object of type T with the data for the IP address or null if no information could be found for the given IP address * @throws IOException if there is an error opening or reading from the file. */ private <T> T get(InetAddress ipAddress, Class<T> cls, boolean hasTraits, String type) throws IOException { String databaseType = this.getMetadata().getDatabaseType(); if (!databaseType.contains(type)) { String caller = Thread.currentThread().getStackTrace()[2].getMethodName(); throw new UnsupportedOperationException("Invalid attempt to open a " + databaseType + " database using the " + caller + " method"); } ObjectNode node = (ObjectNode) this.reader.get(ipAddress); if (node == null) { return null; } InjectableValues inject = new JsonInjector(ipAddress.getHostAddress()); return this.om.reader(inject).treeToValue(node, cls); }
/** * {@inheritDoc} */ @Override public <T> List<T> getValues(final Class<T> cls) throws JsonProcessingException, ScimException { ArrayList<T> objects = new ArrayList<T>(value.size()); for(JsonNode node : value) { objects.add(JsonUtils.getObjectReader().treeToValue(node, cls)); } return objects; }
/** * {@inheritDoc} */ @Override public <T> List<T> getValues(final Class<T> cls) throws JsonProcessingException, ScimException { ArrayList<T> objects = new ArrayList<T>(value.size()); for(JsonNode node : value) { objects.add(JsonUtils.getObjectReader().treeToValue(node, cls)); } return objects; }
/** * {@inheritDoc} */ @Override public <T> T getValue(final Class<T> cls) throws JsonProcessingException, ScimException, IllegalArgumentException { if(value.isArray()) { throw new IllegalArgumentException("Patch operation contains " + "multiple values"); } return JsonUtils.getObjectReader().treeToValue(value, cls); }
/** * {@inheritDoc} */ @Override public <T> T getValue(final Class<T> cls) throws JsonProcessingException, ScimException, IllegalArgumentException { if(value.isArray()) { throw new IllegalArgumentException("Patch operation contains " + "multiple values"); } return JsonUtils.getObjectReader().treeToValue( value, cls); }
/** * {@inheritDoc} */ @Override public <T> List<T> getValues(final Class<T> cls) throws JsonProcessingException, ScimException { ArrayList<T> objects = new ArrayList<T>(value.size()); for(JsonNode node : value) { objects.add(JsonUtils.getObjectReader().treeToValue(node, cls)); } return objects; }
/** * {@inheritDoc} */ @Override public <T> T getValue(final Class<T> cls) throws JsonProcessingException, ScimException, IllegalArgumentException { if(value.isArray()) { throw new IllegalArgumentException("Patch operation contains " + "multiple values"); } return JsonUtils.getObjectReader().treeToValue(value, cls); }
/** * {@inheritDoc} */ @Override public <T> List<T> getValues(final Class<T> cls) throws JsonProcessingException, ScimException { ArrayList<T> objects = new ArrayList<T>(value.size()); for(JsonNode node : value) { objects.add(JsonUtils.getObjectReader().treeToValue(node, cls)); } return objects; }
/** * {@inheritDoc} */ @Override public <T> T getValue(final Class<T> cls) throws JsonProcessingException, ScimException, IllegalArgumentException { if(value.isArray()) { throw new IllegalArgumentException("Patch operation contains " + "multiple values"); } return JsonUtils.getObjectReader().treeToValue( value, cls); }
@Override public <T> List<T> asList(Class<T> tClazz) throws JWTDecodeException { if (!data.isArray()) { return null; } List<T> list = new ArrayList<>(); for (int i = 0; i < data.size(); i++) { try { list.add(objectReader.treeToValue(data.get(i), tClazz)); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e); } } return list; }
@Override @SuppressWarnings("unchecked") public <T> T[] asArray(Class<T> tClazz) throws JWTDecodeException { if (!data.isArray()) { return null; } T[] arr = (T[]) Array.newInstance(tClazz, data.size()); for (int i = 0; i < data.size(); i++) { try { arr[i] = objectReader.treeToValue(data.get(i), tClazz); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e); } } return arr; }
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; }
public static MessageThread parse(String json) throws IOException { // Point at "data" within larger body of JSON JsonNode data = reader.readTree(json).at(dataPointer); // Convert "data" to MessageThread return reader.treeToValue(data, MessageThread.class); } }
public static MessageThread parse(String json) throws IOException { // Point at "data" within larger body of JSON JsonNode data = reader.readTree(json).at(dataPointer); // Convert "data" to MessageThread return reader.treeToValue(data, MessageThread.class); } }
/** * @param ipAddress IPv4 or IPv6 address to lookup. * @return A <T> object with the data for the IP address * @throws IOException if there is an error opening or reading from the file. * @throws AddressNotFoundException if the IP address is not in our database */ private <T> T get(InetAddress ipAddress, Class<T> cls, String type) throws IOException, AddressNotFoundException { String databaseType = this.getMetadata().getDatabaseType(); if (!databaseType.contains(type)) { String caller = Thread.currentThread().getStackTrace()[2] .getMethodName(); throw new UnsupportedOperationException( "Invalid attempt to open a " + databaseType + " database using the " + caller + " method"); } ObjectNode node = jsonNodeToObjectNode(reader.get(ipAddress)); // We throw the same exception as the web service when an IP is not in // the database if (node == null) { throw new AddressNotFoundException("The address " + ipAddress.getHostAddress() + " is not in the database."); } InjectableValues inject = new JsonInjector(locales, ipAddress.getHostAddress()); return this.om.reader(inject).treeToValue(node, cls); }
/** * @param ipAddress IPv4 or IPv6 address to lookup. * @return A <T> object with the data for the IP address * @throws IOException if there is an error opening or reading from the file. * @throws AddressNotFoundException if the IP address is not in our database */ private <T> T get(InetAddress ipAddress, Class<T> cls, String type) throws IOException, AddressNotFoundException { String databaseType = this.getMetadata().getDatabaseType(); if (!databaseType.contains(type)) { String caller = Thread.currentThread().getStackTrace()[2] .getMethodName(); throw new UnsupportedOperationException( "Invalid attempt to open a " + databaseType + " database using the " + caller + " method"); } ObjectNode node = jsonNodeToObjectNode(reader.get(ipAddress)); // We throw the same exception as the web service when an IP is not in // the database if (node == null) { throw new AddressNotFoundException("The address " + ipAddress.getHostAddress() + " is not in the database."); } InjectableValues inject = new JsonInjector(locales, ipAddress.getHostAddress()); return this.om.reader(inject).treeToValue(node, cls); }