本文整理匯總了Java中com.google.gson.stream.JsonWriter.setLenient方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonWriter.setLenient方法的具體用法?Java JsonWriter.setLenient怎麽用?Java JsonWriter.setLenient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gson.stream.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.setLenient方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: toString
import com.google.gson.stream.JsonWriter; //導入方法依賴的package包/類
public String toString() {
try {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.setLenient(true);
Streams.write(this, jsonWriter);
return stringWriter.toString();
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例4: toString
import com.google.gson.stream.JsonWriter; //導入方法依賴的package包/類
/**
* Returns a String representation of this element.
*/
@Override
public String toString() {
try {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.setLenient(true);
Streams.write(this, jsonWriter);
return stringWriter.toString();
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例5: setWriterOptions
import com.google.gson.stream.JsonWriter; //導入方法依賴的package包/類
void setWriterOptions(JsonWriter writer) {
writer.setSerializeNulls(serializeNulls);
writer.setLenient(lenient);
writer.setHtmlSafe(htmlSafe);
writer.setIndent(prettyPrinting ? " " : "");
}