本文整理汇总了Java中com.google.gson.stream.JsonWriter.setHtmlSafe方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.setHtmlSafe方法的具体用法?Java JsonWriter.setHtmlSafe怎么用?Java JsonWriter.setHtmlSafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.setHtmlSafe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException {
TypeAdapter<?> adapter = getAdapter(TypeToken.get(typeOfSrc));
boolean oldLenient = writer.isLenient();
writer.setLenient(true);
boolean oldHtmlSafe = writer.isHtmlSafe();
writer.setHtmlSafe(this.htmlSafe);
boolean oldSerializeNulls = writer.getSerializeNulls();
writer.setSerializeNulls(this.serializeNulls);
try {
adapter.write(writer, src);
writer.setLenient(oldLenient);
writer.setHtmlSafe(oldHtmlSafe);
writer.setSerializeNulls(oldSerializeNulls);
} catch (Throwable e) {
throw new JsonIOException(e);
} catch (Throwable th) {
writer.setLenient(oldLenient);
writer.setHtmlSafe(oldHtmlSafe);
writer.setSerializeNulls(oldSerializeNulls);
}
}
示例2: toJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
* Writes the JSON representation of {@code src} of type {@code typeOfSrc} to
* {@code writer}.
* @throws JsonIOException if there was a problem writing to the writer
*/
@SuppressWarnings("unchecked")
public void toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException {
TypeAdapter<?> adapter = getAdapter(TypeToken.get(typeOfSrc));
boolean oldLenient = writer.isLenient();
writer.setLenient(true);
boolean oldHtmlSafe = writer.isHtmlSafe();
writer.setHtmlSafe(htmlSafe);
boolean oldSerializeNulls = writer.getSerializeNulls();
writer.setSerializeNulls(serializeNulls);
try {
((TypeAdapter<Object>) adapter).write(writer, src);
} catch (IOException e) {
throw new JsonIOException(e);
} finally {
writer.setLenient(oldLenient);
writer.setHtmlSafe(oldHtmlSafe);
writer.setSerializeNulls(oldSerializeNulls);
}
}
示例3: setWriterOptions
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
void setWriterOptions(JsonWriter writer) {
writer.setSerializeNulls(serializeNulls);
writer.setLenient(lenient);
writer.setHtmlSafe(htmlSafe);
writer.setIndent(prettyPrinting ? " " : "");
}