Jackson中JsonGenerator使用示例

import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class JsonGeneratorDemo {
    @Test
    public void test() throws IOException {
        JsonFactory factory = new JsonFactory();

        JsonGenerator generator = factory.createGenerator(
                new File("src/data/output.json"), JsonEncoding.UTF8);

        generator.writeStartObject();
        generator.writeStringField("brand", "Mercedes");
        generator.writeNumberField("doors", 6);
        generator.writeEndObject();

        generator.close();
    }
}
上一篇:kubernetes 1.8 高可用安装(二)


下一篇:Struts2远程代码执行漏洞CVE-2017-9805 s2-052 绿盟科技发布扫描工具