Package com.badlogic.gdx.utils
Class JsonWriter
- java.lang.Object
-
- java.io.Writer
-
- com.badlogic.gdx.utils.JsonWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class JsonWriter extends java.io.Writer
Builder style API for emitting JSON.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonWriter.OutputType
-
Constructor Summary
Constructors Constructor Description JsonWriter(java.io.Writer writer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonWriter
array()
JsonWriter
array(java.lang.String name)
void
close()
void
flush()
java.io.Writer
getWriter()
JsonWriter
json(java.lang.String json)
Writes the specified JSON value, without quoting or escaping.JsonWriter
json(java.lang.String name, java.lang.String json)
Writes the specified JSON value, without quoting or escaping.JsonWriter
name(java.lang.String name)
JsonWriter
object()
JsonWriter
object(java.lang.String name)
JsonWriter
pop()
JsonWriter
set(java.lang.String name, java.lang.Object value)
void
setOutputType(JsonWriter.OutputType outputType)
Sets the type of JSON output.void
setQuoteLongValues(boolean quoteLongValues)
When true, quotes long, double, BigInteger, BigDecimal types to prevent truncation in languages like JavaScript and PHP.JsonWriter
value(java.lang.Object value)
void
write(char[] cbuf, int off, int len)
-
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
-
setOutputType
public void setOutputType(JsonWriter.OutputType outputType)
Sets the type of JSON output. Default isJsonWriter.OutputType.minimal
.
-
setQuoteLongValues
public void setQuoteLongValues(boolean quoteLongValues)
When true, quotes long, double, BigInteger, BigDecimal types to prevent truncation in languages like JavaScript and PHP. This is not necessary when using libgdx, which handles these types without truncation. Default is false.
-
name
public JsonWriter name(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
object
public JsonWriter object() throws java.io.IOException
- Throws:
java.io.IOException
-
array
public JsonWriter array() throws java.io.IOException
- Throws:
java.io.IOException
-
value
public JsonWriter value(java.lang.Object value) throws java.io.IOException
- Throws:
java.io.IOException
-
json
public JsonWriter json(java.lang.String json) throws java.io.IOException
Writes the specified JSON value, without quoting or escaping.- Throws:
java.io.IOException
-
object
public JsonWriter object(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
array
public JsonWriter array(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
set
public JsonWriter set(java.lang.String name, java.lang.Object value) throws java.io.IOException
- Throws:
java.io.IOException
-
json
public JsonWriter json(java.lang.String name, java.lang.String json) throws java.io.IOException
Writes the specified JSON value, without quoting or escaping.- Throws:
java.io.IOException
-
pop
public JsonWriter pop() throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOException
- Specified by:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
- Throws:
java.io.IOException
-
-