Package com.cedarsoftware.io
Interface JsonClassWriter<T>
- Type Parameters:
T- the type of object this writer handles
- All Known Subinterfaces:
JsonWriter.JsonClassWriter<T>
- All Known Implementing Classes:
AtomicIntegerArrayWriter,AtomicLongArrayWriter,BitSetWriter,ByteArrayWriter,ByteBufferWriter,CharBufferWriter,CompactMapWriter,CompactSetWriter,CountDownLatchWriter,LongWriter,MultiKeyMapWriter,OptionalWriter,ReentrantLockWriter,ReentrantReadWriteLockWriter,SemaphoreWriter,Writers.BigDecimalWriter,Writers.BigIntegerWriter,Writers.CalendarWriter,Writers.CharacterWriter,Writers.ClassWriter,Writers.CurrencyWriter,Writers.DateAsLongWriter,Writers.DateWriter,Writers.DoubleWriter,Writers.DurationWriter,Writers.EnumsAsStringWriter,Writers.FloatingPointWriter,Writers.FloatWriter,Writers.InstantWriter,Writers.JsonStringWriter,Writers.LocalDateAsLong,Writers.LocalDateTimeWriter,Writers.LocalDateWriter,Writers.LocaleWriter,Writers.LocalTimeWriter,Writers.MonthDayWriter,Writers.OffsetDateTimeWriter,Writers.OffsetTimeWriter,Writers.PatternWriter,Writers.PeriodWriter,Writers.PrimitiveTypeWriter,Writers.PrimitiveUtf8StringWriter,Writers.PrimitiveValueWriter,Writers.TimestampWriter,Writers.TimeZoneWriter,Writers.UUIDWriter,Writers.YearMonthWriter,Writers.YearWriter,Writers.ZonedDateTimeWriter,Writers.ZoneOffsetWriter,ZoneIdWriter
public interface JsonClassWriter<T>
Implement this interface to customize the JSON output for a given class.
Register your custom writer using WriteOptionsBuilder.addCustomWrittenClass(Class, JsonClassWriter).
- Author:
- John DeRegnaucourt (jdereg@gmail.com)
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringGet the type name to use for @type when writing this object.default booleanhasPrimitiveForm(WriterContext context) Indicates whether this class has a primitive (non-object) JSON form.default voidwrite(T o, boolean showType, Writer output, WriterContext context) Write the object in JSON format to the output Writer.default voidwritePrimitiveForm(Object o, Writer output, WriterContext context) Write the object in its primitive JSON form (without surrounding braces).
-
Method Details
-
write
Write the object in JSON format to the output Writer.- Parameters:
o- Object to be written in JSON formatshowType- boolean indicating whether to include @type in the outputoutput- Writer destination where the JSON is writtencontext- WriterContext providing access to WriteOptions and other write utilities- Throws:
IOException- if an I/O error occurs during writing
-
hasPrimitiveForm
Indicates whether this class has a primitive (non-object) JSON form. Most custom writers will not have a primitive form, so the default is false.- Parameters:
context- WriterContext providing access to WriteOptions- Returns:
- true if this class can be written as a JSON primitive value
-
writePrimitiveForm
Write the object in its primitive JSON form (without surrounding braces). Only called ifhasPrimitiveForm(WriterContext)returns true.- Parameters:
o- Object to be writtenoutput- Writer destination where the JSON is writtencontext- WriterContext providing access to WriteOptions and writing tools- Throws:
IOException- if an I/O error occurs during writing
-
getTypeName
Get the type name to use for @type when writing this object. Override to provide a custom type name.- Parameters:
o- the object being written- Returns:
- the type name string (defaults to the object's class name)
-