class JsonCoercingUtil {

  public static Object parseLiteral(Object input, Map<String, Object> variables) throws CoercingParseLiteralException {
    if (!(input instanceof Value)) {
      log.error("Expected 'Value', got: {}", input);
      throw new CoercingParseLiteralException("Expected 'Value', got: " + input);
    }
    Object result = null;
    if (input instanceof StringValue) {
      result = ((StringValue) input).getValue();
    } else if (input instanceof IntValue) {
      result = ((IntValue) input).getValue();
    } else if (input instanceof FloatValue) {
      result = ((FloatValue) input).getValue();
    } else if (input instanceof BooleanValue) {
      result = ((BooleanValue) input).isValue();
    } else if (input instanceof EnumValue) {
      result = ((EnumValue) input).getName();
    } else if (input instanceof VariableReference) {
      result = variables.get(((VariableReference) input).getName());
    } else if (input instanceof ArrayValue) {
      result = ((ArrayValue) input).getValues().stream()
          .map(v -> parseLiteral(v, variables))
          .collect(toList());
    } else if (input instanceof ObjectValue) {
      result = ((ObjectValue) input).getObjectFields().stream()
          .collect(toMap(ObjectField::getName, f -> parseLiteral(f.getValue(), variables)));
    }
    return result;
  }

}