@FunctionalInterface 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.
This interface includes some default methods, which were introduced in Java 8. If you want to make this library work with Java 7, then change those to regular public interface signatures and comment out the rest of the code for the default methods.
| Modifier and Type | Method and Description |
|---|---|
default String |
toJSON()
Convert this object to a string of JSON data.
|
default 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.
|
default void |
toJSON(Writer json)
Write to the given writer as JSON data using all
defaults for the configuration.
|
default 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) to
actually do the work.
default 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.default void toJSON(Writer json) throws IOException
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 © 2015. All rights reserved.