java 说明如何使用Jolt实现JSON转换。在此示例中,JSON文件是内存中的字符串。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 说明如何使用Jolt实现JSON转换。在此示例中,JSON文件是内存中的字符串。相关的知识,希望对你有一定的参考价值。
// Adapted from: https://github.com/bazaarvoice/jolt/blob/master/gettingStarted.md
// https://mvnrepository.com/artifact/com.bazaarvoice.jolt/json-utils
// https://mvnrepository.com/artifact/com.bazaarvoice.jolt/jolt-core
import com.bazaarvoice.jolt.Chainr;
import com.bazaarvoice.jolt.JsonUtils;
import java.util.List;
public class JoltChainrDemo {
public static void main(String[] args) throws Exception {
// This stylesheet performs an identity transform.
String spec = "[{\"operation\":\"shift\",\"spec\":{\"*\":\"&0\"}}]";
// Input JSON document.
String json = "{\"foo\":\"bar\"}";
// Setup the machine.
List chainrSpecJSON = JsonUtils.jsonToList(spec);
Chainr chainr = Chainr.fromSpec(chainrSpecJSON);
Object inputJSON = JsonUtils.jsonToObject(json);
// Do the transformation.
Object transformedOutput = chainr.transform(inputJSON);
// The output in this case will look like the input.
System.out.println(JsonUtils.toJsonString(transformedOutput));
}
}
以上是关于java 说明如何使用Jolt实现JSON转换。在此示例中,JSON文件是内存中的字符串。的主要内容,如果未能解决你的问题,请参考以下文章