Package com.cedarsoftware.util.io
Interface JsonWriter.JsonClassWriter
-
- All Superinterfaces:
JsonWriter.JsonClassWriterBase
- All Known Subinterfaces:
JsonWriter.JsonClassWriterEx
- All Known Implementing Classes:
Writers.AtomicBooleanWriter
,Writers.AtomicIntegerWriter
,Writers.AtomicLongWriter
,Writers.BigDecimalWriter
,Writers.BigIntegerWriter
,Writers.CalendarWriter
,Writers.ClassWriter
,Writers.DateWriter
,Writers.DefaultEnumWriter
,Writers.EnumAsPrimitiveWriter
,Writers.JsonStringWriter
,Writers.LocaleWriter
,Writers.PrimitiveTypeWriter
,Writers.PrimitiveUtf8StringWriter
,Writers.PrimitiveValueWriter
,Writers.StringBufferWriter
,Writers.StringBuilderWriter
,Writers.TimestampWriter
,Writers.TimeZoneWriter
,Writers.URLWriter
,Writers.UUIDWriter
- Enclosing class:
- JsonWriter
public static interface JsonWriter.JsonClassWriter extends JsonWriter.JsonClassWriterBase
Implement this interface to customize the JSON output for a given class.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default JsonWriter
getWriter(Map<String,Object> args)
return the JsonWriter instance performing the overall work.default boolean
hasPrimitiveForm()
default void
write(Object o, boolean showType, Writer output)
When write() is called, it is expected that subclasses will write the appropriate JSON to the passed in Writer.default void
write(Object o, boolean showType, Writer output, Map<String,Object> args)
When write() is called, it is expected that subclasses will write the appropriate JSON to the passed in Writer.default void
writePrimitiveForm(Object o, Writer output)
This method will be called to write the item in primitive form (if the response to hasPrimitiveForm() was true).default void
writePrimitiveForm(Object o, Writer output, Map args)
This default implementation will call the more basic writePrimitiveForm that does not take arguments.
-
-
-
Method Detail
-
write
default void write(Object o, boolean showType, Writer output, Map<String,Object> args) throws IOException
When write() is called, it is expected that subclasses will write the appropriate JSON to the passed in Writer.- Parameters:
o
- Object to be written in JSON format.showType
- boolean indicating whether to show @type.output
- Writer destination to where the actual JSON is written.args
- Map of 'settings' arguments initially passed into the JsonWriter.- Throws:
IOException
- if thrown by the writer. Will be caught at a higher level and wrapped in JsonIoException.
-
write
default void write(Object o, boolean showType, Writer output) throws IOException
When write() is called, it is expected that subclasses will write the appropriate JSON to the passed in Writer.- Parameters:
o
- Object to be written in JSON format.showType
- boolean indicating whether to show @type.output
- Writer destination to where the actual JSON is written.- Throws:
IOException
- if thrown by the writer. Will be caught at a higher level and wrapped in JsonIoException.
-
hasPrimitiveForm
default boolean hasPrimitiveForm()
- Returns:
- boolean true if the class being written has a primitive (non-object) form. Default is false since most custom writers will not have a primitive form.
-
writePrimitiveForm
default void writePrimitiveForm(Object o, Writer output, Map args) throws IOException
This default implementation will call the more basic writePrimitiveForm that does not take arguments. No need to override this method unless you need access to the args.- Parameters:
o
- Object to be writtenoutput
- Writer destination to where the actual JSON is written.args
- Map of 'settings' arguments initially passed into the JsonWriter.- Throws:
IOException
- if thrown by the writer. Will be caught at a higher level and wrapped in JsonIoException.
-
writePrimitiveForm
default void writePrimitiveForm(Object o, Writer output) throws IOException
This method will be called to write the item in primitive form (if the response to hasPrimitiveForm() was true). Override this method if you have a primitive form and need to access the arguments that kicked off the JsonWriter.- Parameters:
o
- Object to be writtenoutput
- Writer destination to where the actual JSON is written.- Throws:
IOException
- if thrown by the writer. Will be caught at a higher level and wrapped in JsonIoException.
-
getWriter
default JsonWriter getWriter(Map<String,Object> args)
return the JsonWriter instance performing the overall work. This can be used to do some of the safe writes and utf8 writes that JsonWriter provides.- Parameters:
args
- Map of settings initially passed to JsonWriter.- Returns:
- JsonWriter instance performing the work.
-
-