### Question:
JsonValues { public static String evaluate(JsonValue value) { Expression<String> expression = asExpression(value, String.class); if (expression != null) { return expression.eval(); } return null; } private  JsonValues(); static Class<?> asClass(JsonValue value); @SuppressWarnings("unchecked") static T asNewInstance(JsonValue value, Class<T> type); static Expression<T> asExpression(JsonValue value, Class<T> expectedType); static String evaluate(JsonValue value); static JsonValue evaluate(final JsonValue value, final Logger logger); static JsonValue evaluateJsonStaticExpression(final JsonValue value); static JsonValue firstOf(final JsonValue config, final String... names); static Function<JsonValue, Expression<String>, HeapException> ofExpression(); static Function<JsonValue, T, HeapException> ofRequiredHeapObject(final Heap heap,
                                                                                 final Class<T> type); static Function<JsonValue, T, HeapException> ofEnum(final Class<T> enumType); static JsonValue getWithDeprecation(JsonValue config, Logger logger, String name,
            String... deprecatedNames); static void warnForDeprecation(final JsonValue config, final Logger logger,
            final String name, final String deprecatedName);  }### Answer:
@Test public void shouldEvaluateObject() throws Exception { final JsonValue value = json(object( field("string", "${decodeBase64('VGhpcyBtZXRob2Q=')}"), field("array", array("${decodeBase64('ZXZhbHVhdGVz')}")), field("map", object(field("mapField", "${decodeBase64('YWxsIHN0cmluZyBleHByZXNzaW9ucw==')}"))), field("set", set("${decodeBase64('aW4gdGhlIGdpdmVuIG9iamVjdA==')}")))); final JsonValue transformed = evaluate(value, logger); assertThat(transformed.get("string").asString()).isEqualTo("This method"); assertThat(transformed.get("array").get(0).asString()).isEqualTo("evaluates"); assertThat(transformed.get("map").get("mapField").asString()).isEqualTo("all string expressions"); assertThat(transformed.get("set").iterator().next().asString()).isEqualTo("in the given object"); verifyZeroInteractions(logger); }
@Test public void shouldEvaluateObjectWithTypeTransformation() throws Exception { JsonValue value = json(object(field("boolean", "${true}"), field("array", "${array('one', 'two', 'three')}"), field("properties", "${system}"))); JsonValue transformed = evaluate(value, logger); assertThat(transformed.get("boolean").asBoolean()).isTrue(); assertThat((String[]) transformed.get("array").getObject()).containsExactly("one", "two", "three"); assertThat(transformed.get("properties").asMap(String.class)).containsKey("user.dir"); verifyZeroInteractions(logger); }
@Test public void shouldEvaluateObjectWhenAttributeEvaluationFails() throws Exception { final JsonValue value = json(object(field("string", "${decodeBase64('notBase64')}"))); final JsonValue transformed = evaluate(value, logger); assertThat(transformed.get("string").asString()).isNull(); verify(logger).warning(anyString()); }
@Test public void shouldEvaluateObjectWhenAttributeIsNotAnExpression() throws Exception { final JsonValue value = json(object(field("string", "$$$${{"))); final JsonValue transformed = evaluate(value, logger); assertThat(transformed.get("string").asString()).isEqualTo("$$$${{"); verify(logger).warning(anyString()); }