Config { @SuppressWarnings("unchecked") public <E> Optional<E> getOptional(String key, Class<E> type) { return (Optional<E>) get(key, mapper.getTypeFactory().constructReferenceType(Optional.class, mapper.getTypeFactory().constructType(type)), Optional.<E>absent()); } Config(ObjectMapper mapper);   Config(ObjectMapper mapper, JsonNode object); protected  Config(Config config); @JsonCreator static Config deserializeFromJackson(@JacksonInject ObjectMapper mapper, JsonNode object); @JsonValue ObjectNode getInternalObjectNode(); Config set(String key, Object v); Config setOptional(String key, Optional<?> v); Config setIfNotSet(String key, Object v); Config setNested(String key, Config v); Config setAll(Config other); Config setAllIfNotSet(Config other); Config remove(String key); Config deepCopy(); Config merge(Config other); Config mergeDefault(Config other); ConfigFactory getFactory(); List<String> getKeys(); boolean isEmpty(); boolean has(String key); E convert(Class<E> type); E get(String key, Class<E> type); Object get(String key, JavaType type); @SuppressWarnings("unchecked") E get(String key, TypeReference<E> type); E get(String key, Class<E> type, E defaultValue); Object get(String key, JavaType type, Object defaultValue); @SuppressWarnings("unchecked") E get(String key, TypeReference<E> type, E defaultValue); @SuppressWarnings("unchecked") Optional<E> getOptional(String key, Class<E> type); @SuppressWarnings("unchecked") Optional<E> getOptional(String key, TypeReference<E> type); @SuppressWarnings("unchecked") List<E> getList(String key, Class<E> elementType); @SuppressWarnings("unchecked") List<E> getListOrEmpty(String key, Class<E> elementType); @SuppressWarnings("unchecked") List<E> parseList(String key, Class<E> elementType); @SuppressWarnings("unchecked") List<E> parseListOrGetEmpty(String key, Class<E> elementType); @SuppressWarnings("unchecked") Map<K, V> getMap(String key, Class<K> keyType, Class<V> valueType); @SuppressWarnings("unchecked") Map<K, V> getMapOrEmpty(String key, Class<K> keyType, Class<V> valueType); Config getNested(String key); Config parseNested(String key); Config parseNestedOrGetEmpty(String key); Config getNestedOrSetEmpty(String key); Config getNestedOrGetEmpty(String key); Config getNestedOrderedOrGetEmpty(String key); Optional<Config> getOptionalNested(String key); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testGetOptional() { config.set("str", "s"); assertThat(config.getOptional("str", JsonNode.class).transform(JsonNode::deepCopy), is(Optional.of(TextNode.valueOf("s")))); }