public interface JSONAble
JSONUtil.toJSON(Object, JSONConfig) encounters one of these objects
as one of its property values, it will call this method in those objects to
convert them to JSON.
The Java 8 version of this interface includes default versions of 3 of the 4 methods and is a functional interface allowing its use in Java 8 Lambda expressions. Java 7 and earlier do not support default methods in interfaces or functional interfaces so those features have been removed from the Java 7 and earlier versions of this interface.
| Modifier and Type | Method and Description |
|---|---|
String |
toJSON()
Convert this object to a string of JSON data.
|
String |
toJSON(JSONConfig jsonConfig)
Convert this object to a string of JSON data.
|
void |
toJSON(JSONConfig jsonConfig,
Writer json)
Write this object to the given writer as JSON data.
|
void |
toJSON(Writer json)
Write to the given writer as JSON data using all defaults for the
configuration.
|
String toJSON()
This version does not use a JSONConfig and so can break loop
detection. In many common cases, that's not a problem and this is just
more convenient.
The default implementation calls toJSON(JSONConfig, Writer) to
actually do the work.
String toJSON(JSONConfig jsonConfig)
Implementations which use JSONUtil to generate their JSON should
pass the supplied JSONConfig to
JSONUtil.toJSON(Object, JSONConfig) or
JSONUtil.toJSON(Object, JSONConfig, Writer) in order to preserve
data structure loop detection. If this is not done, then loops may not be
detected properly.
The default implementation calls toJSON(JSONConfig, Writer) to
actually do the work.
jsonConfig - A configuration object to use to optionally set encoding options.void toJSON(Writer json) throws IOException
The default implementation calls toJSON(JSONConfig, Writer) to
actually do the work.
json - json A writer for the output.IOException - If there is an error on output.void toJSON(JSONConfig jsonConfig, Writer json) throws IOException
Implementations which use JSONUtil to generate their JSON should
pass the supplied JSONConfig to
JSONUtil.toJSON(Object, JSONConfig) or
JSONUtil.toJSON(Object, JSONConfig, Writer) in order to preserve
data structure loop detection. If this is not done, then loops may not be
detected properly.
jsonConfig - A configuration object to use to optionally set encoding options.json - A writer for the output.IOException - If there is an error on output.Copyright © 2016. All rights reserved.