package io.vertx.ext.web.templ.handlebars.impl;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.Set;
import com.github.jknack.handlebars.ValueResolver;
import io.vertx.core.json.JsonObject;
public class JsonObjectValueResolver implements ValueResolver {
public static final ValueResolver INSTANCE = new JsonObjectValueResolver();
@Override
public Object resolve(final Object context, final String name) {
Object value = null;
if (context instanceof JsonObject) {
value = ((JsonObject) context).getValue(name);
}
return value == null ? UNRESOLVED : value;
}
@Override
public Object resolve(final Object context) {
if (context instanceof JsonObject) {
return context;
}
return UNRESOLVED;
}
@Override
public Set<Entry<String, Object>> propertySet(final Object context) {
if (context instanceof JsonObject) {
return ((JsonObject) context).getMap().entrySet();
}
return Collections.emptySet();
}
}