T - the type of objects that this ObjectWriter can serializepublic interface ObjectWriter<T>
This interface supports various features including:
Example usage:
// Get an ObjectWriter for a specific type
ObjectWriter<User> writer = JSONFactory.getDefaultObjectWriterProvider().getObjectWriter(User.class);
// Write to JSON string
User user = new User(1, "John");
String jsonString = writer.toJSONString(user);
// Write to JSONWriter
try (JSONWriter jsonWriter = JSONWriter.of()) {
writer.write(jsonWriter, user);
String result = jsonWriter.toString();
}
| Modifier and Type | Method and Description |
|---|---|
default long |
getFeatures()
Gets the features enabled by this ObjectWriter.
|
default java.lang.Object |
getFieldValue(java.lang.Object object,
java.lang.String fieldName)
Gets the value of a field from the specified object.
|
default FieldWriter |
getFieldWriter(long hashCode)
Gets the FieldWriter for the specified field hash code.
|
default FieldWriter |
getFieldWriter(java.lang.String name)
Gets the FieldWriter for the specified field name.
|
default java.util.List<FieldWriter> |
getFieldWriters()
Gets the list of FieldWriters associated with this ObjectWriter.
|
default boolean |
hasFilter(JSONWriter jsonWriter)
Checks if the JSONWriter has any filters enabled that would affect serialization.
|
default void |
setFilter(Filter filter)
Sets a filter for this ObjectWriter.
|
default void |
setNameFilter(NameFilter nameFilter)
Sets the name filter for this ObjectWriter.
|
default void |
setPropertyFilter(PropertyFilter propertyFilter)
Sets the property filter for this ObjectWriter.
|
default void |
setPropertyPreFilter(PropertyPreFilter propertyPreFilter)
Sets the property pre-filter for this ObjectWriter.
|
default void |
setValueFilter(ValueFilter valueFilter)
Sets the value filter for this ObjectWriter.
|
default java.lang.String |
toJSONString(T object,
JSONWriter.Feature... features)
Converts an object to its JSON string representation using the specified features.
|
default void |
write(JSONWriter jsonWriter,
java.lang.Object object)
Writes an object to the JSONWriter using default parameters.
|
void |
write(JSONWriter jsonWriter,
java.lang.Object object,
java.lang.Object fieldName,
java.lang.reflect.Type fieldType,
long features)
Writes an object to the JSONWriter with the given field name, field type, and features.
|
default void |
writeArrayMapping(JSONWriter jsonWriter,
java.lang.Object object,
java.lang.Object fieldName,
java.lang.reflect.Type fieldType,
long features)
Writes an object to the JSONWriter in array mapping format.
|
default void |
writeArrayMappingJSONB(JSONWriter jsonWriter,
java.lang.Object object)
Writes an object to the JSONWriter in array mapping JSONB format.
|
default void |
writeArrayMappingJSONB(JSONWriter jsonWriter,
java.lang.Object object,
java.lang.Object fieldName,
java.lang.reflect.Type fieldType,
long features)
Writes an object to the JSONWriter in array mapping JSONB format with additional parameters.
|
default void |
writeJSONB(JSONWriter jsonWriter,
java.lang.Object object,
java.lang.Object fieldName,
java.lang.reflect.Type fieldType,
long features)
Writes an object to the JSONWriter in JSONB format.
|
default boolean |
writeTypeInfo(JSONWriter jsonWriter)
Writes type information to the JSON output.
|
default void |
writeWithFilter(JSONWriter jsonWriter,
java.lang.Object object)
Writes an object to the JSONWriter with filter support using default parameters.
|
default void |
writeWithFilter(JSONWriter jsonWriter,
java.lang.Object object,
java.lang.Object fieldName,
java.lang.reflect.Type fieldType,
long features)
Writes an object to the JSONWriter with filter support.
|
default long getFeatures()
default java.util.List<FieldWriter> getFieldWriters()
default FieldWriter getFieldWriter(long hashCode)
hashCode - the hash code of the field namedefault java.lang.Object getFieldValue(java.lang.Object object,
java.lang.String fieldName)
object - the object from which to get the field valuefieldName - the name of the field to getdefault FieldWriter getFieldWriter(java.lang.String name)
name - the name of the fielddefault boolean writeTypeInfo(JSONWriter jsonWriter)
jsonWriter - the JSONWriter to which type information should be writtendefault void writeJSONB(JSONWriter jsonWriter, java.lang.Object object, java.lang.Object fieldName, java.lang.reflect.Type fieldType, long features)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writefieldName - the name of the field being writtenfieldType - the type of the field being writtenfeatures - the features to use for writingdefault void writeArrayMappingJSONB(JSONWriter jsonWriter, java.lang.Object object)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writedefault void writeArrayMappingJSONB(JSONWriter jsonWriter, java.lang.Object object, java.lang.Object fieldName, java.lang.reflect.Type fieldType, long features)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writefieldName - the name of the field being writtenfieldType - the type of the field being writtenfeatures - the features to use for writingdefault void writeArrayMapping(JSONWriter jsonWriter, java.lang.Object object, java.lang.Object fieldName, java.lang.reflect.Type fieldType, long features)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writefieldName - the name of the field being writtenfieldType - the type of the field being writtenfeatures - the features to use for writingdefault boolean hasFilter(JSONWriter jsonWriter)
jsonWriter - the JSONWriter to checkdefault void write(JSONWriter jsonWriter, java.lang.Object object)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writedefault java.lang.String toJSONString(T object, JSONWriter.Feature... features)
object - the object to convert to JSONfeatures - the JSON writer features to usevoid write(JSONWriter jsonWriter, java.lang.Object object, java.lang.Object fieldName, java.lang.reflect.Type fieldType, long features)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writefieldName - the name of the field being writtenfieldType - the type of the field being writtenfeatures - the features to use for writingdefault void writeWithFilter(JSONWriter jsonWriter, java.lang.Object object)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writedefault void writeWithFilter(JSONWriter jsonWriter, java.lang.Object object, java.lang.Object fieldName, java.lang.reflect.Type fieldType, long features)
jsonWriter - the JSONWriter to which the object should be writtenobject - the object to writefieldName - the name of the field being writtenfieldType - the type of the field being writtenfeatures - the features to use for writingjava.lang.UnsupportedOperationException - if the method is not implementeddefault void setPropertyFilter(PropertyFilter propertyFilter)
propertyFilter - the property filter to setdefault void setValueFilter(ValueFilter valueFilter)
valueFilter - the value filter to setdefault void setNameFilter(NameFilter nameFilter)
nameFilter - the name filter to setdefault void setPropertyPreFilter(PropertyPreFilter propertyPreFilter)
propertyPreFilter - the property pre-filter to setdefault void setFilter(Filter filter)
filter - the filter to set