Package org.springframework.boot.json
Interface WritableJson
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
JSON content that can be written out.
- Since:
- 3.4.0
- Author:
- Phillip Webb, Moritz Halbritter
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic WritableJson
of
(WritableJson writableJson) Factory method used to create aWritableJson
with a sensibleObject.toString()
that delegate totoJsonString()
.void
to
(Appendable out) Write the JSON to the providedAppendable
.default byte[]
Write the JSON to a UTF-8 encoded byte array.default byte[]
toByteArray
(Charset charset) Write the JSON to a byte array.default String
Write the JSON to aString
.default void
Write the JSON to the providedOutputStream
usingUTF8
encoding.default void
toOutputStream
(OutputStream out, Charset charset) Write the JSON to the providedOutputStream
using the givenCharset
.default void
Write the JSON to the providedWritableResource
usingUTF8
encoding.default void
toResource
(WritableResource out, Charset charset) Write the JSON to the providedWritableResource
using the givenCharset
.default void
Write the JSON to the providedWriter
.
-
Method Details
-
to
Write the JSON to the providedAppendable
.- Parameters:
out
- theAppendable
to receive the JSON- Throws:
IOException
- on IO error
-
toJsonString
Write the JSON to aString
.- Returns:
- the JSON string
-
toByteArray
default byte[] toByteArray()Write the JSON to a UTF-8 encoded byte array.- Returns:
- the JSON bytes
-
toByteArray
Write the JSON to a byte array.- Parameters:
charset
- the charset- Returns:
- the JSON bytes
-
toResource
Write the JSON to the providedWritableResource
usingUTF8
encoding.- Parameters:
out
- theOutputStream
to receive the JSON- Throws:
IOException
- on IO error
-
toResource
Write the JSON to the providedWritableResource
using the givenCharset
.- Parameters:
out
- theOutputStream
to receive the JSONcharset
- the charset to use- Throws:
IOException
- on IO error
-
toOutputStream
Write the JSON to the providedOutputStream
usingUTF8
encoding. The output stream will not be closed.- Parameters:
out
- theOutputStream
to receive the JSON- Throws:
IOException
- on IO error- See Also:
-
toOutputStream
Write the JSON to the providedOutputStream
using the givenCharset
. The output stream will not be closed.- Parameters:
out
- theOutputStream
to receive the JSONcharset
- the charset to use- Throws:
IOException
- on IO error
-
toWriter
Write the JSON to the providedWriter
. The writer will be flushed but not closed.- Parameters:
out
- theWriter
to receive the JSON- Throws:
IOException
- on IO error- See Also:
-
of
Factory method used to create aWritableJson
with a sensibleObject.toString()
that delegate totoJsonString()
.- Parameters:
writableJson
- the sourceWritableJson
- Returns:
- a new
WritableJson
with a sensibleObject.toString()
.
-