Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JAVA/Interpolation中将字符串评估为json访问_Java_Json_Clojure_Interpolation - Fatal编程技术网

在JAVA/Interpolation中将字符串评估为json访问

在JAVA/Interpolation中将字符串评估为json访问,java,json,clojure,interpolation,Java,Json,Clojure,Interpolation,标题可能是“错误的”,因为我不确定如何总结我试图实现的目标 让我们想象一下(在JAVA上下文中),我有一个DTO文档 public class Document { private String title; private List<Field> fields; // Omitting constructor/getters/setters } public class Field { private String name; priva

标题可能是“错误的”,因为我不确定如何总结我试图实现的目标

让我们想象一下(在JAVA上下文中),我有一个DTO文档

public class Document {
    private String title;
    private List<Field> fields;
    // Omitting constructor/getters/setters

}

public class Field {
    private String name;
    private String value;
}
(这里假设第一个字段有一个整数值,我们暂时不输入类型)

所以我想找一个评估员:

public class Evaluator {
    public Object eval(Document document, String expression) {
        // 1. "put" the document values in the expression, i.e. replace the ${} with proper attirbutes
        // 2. Eval the expression
    }
}
由于会询问许多运算符(数字、日期、自定义运算符),因此我还考虑在此处进行Clojure评估,以便利用宏定义所述运算符。或者使用Javascript脚本引擎(cf.)

但这可能与问题无关,因为我在这里的第一个目标是将${document.fields[0].value}映射到文档的getter(注释中的1)


这件事有什么进展吗?或者我必须手动解析表达式以映射到文档吗?

这一个显然适用于某些夯实引擎,如velocity、freemarker、pebble等。。它们中的大多数都是解决这类任务的优质动力工具,您不必在这里重新发明轮子。听起来您想要做的事情与类似,但它的目的是解析JSON字符串。谢谢,模板确实可以完成这项工作!
public class Evaluator {
    public Object eval(Document document, String expression) {
        // 1. "put" the document values in the expression, i.e. replace the ${} with proper attirbutes
        // 2. Eval the expression
    }
}