本文整理了Java中leap.lang.json.JSON.writer()
方法的一些代码示例,展示了JSON.writer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.writer()
方法的具体详情如下:
包路径:leap.lang.json.JSON
类名称:JSON
方法名:writer
[英]Returns the JsonWriterCreator for creating a new JsonWriter.
[中]返回用于创建新JsonWriter的JsonWriterCreator。
代码示例来源:origin: org.leapframework/leap-lang
/**
* Creates a {@link JsonWriter} use {@link StringBuilder} as output.
*/
public static JsonWriter createWriter(JsonSettings settings) {
return writer().setSettings(settings).create();
}
代码示例来源:origin: org.leapframework/leap-lang
/**
* Creates a {@link JsonWriter} use the given {@link Appendable} as output.
*/
public static JsonWriter createWriter(Appendable out, JsonSettings settings) {
return writer(out).setSettings(settings).create();
}
代码示例来源:origin: org.leapframework/leap-webapi
protected JsonWriter createJsonWriter(Appendable out) {
JsonWriterCreator writer = JSON.writer(out);
if(null != propertyNamingStyle) {
writer.setNamingStyle(propertyNamingStyle);
}
return writer.create();
}
代码示例来源:origin: org.leapframework/leap-lang
default void toJson(Appendable out) {
toJson(JSON.writer(out).setIgnoreNull(true).create());
}
代码示例来源:origin: org.leapframework/leap-lang
default void toJson(Appendable out, JsonSettings settings){
if(settings == null){
toJson(out);
return;
}
JsonWriter writer = JSON.writer(out)
.setSettings(settings)
.create();
toJson(writer);
}
代码示例来源:origin: org.leapframework/leap-spring-boot-web
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
try (OutputStream os = outputMessage.getBody()){
try (OutputStreamWriter writer = new OutputStreamWriter(os, getCharset(outputMessage))) {
JsonWriter jsonWriter = JSON.writer(writer).create();
if(o == null) {
jsonWriter.null_();
return;
}
if(o.getClass().isArray()) {
Object[] a = (Object[])o;
jsonWriter.startArray();
for(Object item : a) {
((JsonStringable)item).toJson(jsonWriter);
}
jsonWriter.endArray();
}else {
((JsonStringable)o).toJson(jsonWriter);
}
}
}
}
代码示例来源:origin: org.leapframework/leap-spring-boot-web
@Override
public void write(Object o, Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if(type instanceof Class) {
writeInternal(o, outputMessage);
}else {
try (OutputStream os = outputMessage.getBody()){
try (OutputStreamWriter writer = new OutputStreamWriter(os, getCharset(outputMessage))) {
JsonWriter jsonWriter = JSON.writer(writer).create();
if(null == o) {
jsonWriter.startArray().endArray();
return;
}
Collection c = (Collection)o;
jsonWriter.array(c, item -> {
((JsonStringable)item).toJson(jsonWriter);
});
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!