Class JsonPatchMarshaller
JsonSerializer and JsonParser into a single class with convenience to/of methods,
pre-wired for JSON Patch's JsonPatchOperation discriminator.
Every JsonSerializer/JsonParser used to read or write JsonPatchOperation (or
JsonPatch) needs to be configured with
AddOp, RemoveOp, ReplaceOp, MoveOp, CopyOp, and TestOp resolves
via the RFC 6902 "op" member rather than the default "_type" property. This class hand-wires
that configuration once so callers don't have to repeat it.
Examples:
Example output:
[{
See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonPatchMarshallerDefault marshaller instance.static final JsonParserstatic final JsonSerializer -
Constructor Summary
ConstructorsConstructorDescriptionCreates using the pre-wiredSERIALIZERandPARSER.Creates with custom serializer and parser. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringSerializes a POJO to aString using theDEFAULTmarshaller.static voidstatic <T> Tstatic <T> Tstatic <T> TParses an input into the specified object type using theDEFAULTmarshaller.static <T> TParses an input into the specified parameterized object type using theDEFAULTmarshaller.Methods inherited from class org.apache.juneau.marshall.marshaller.CharMarshaller
read, read, writeMethods inherited from class org.apache.juneau.marshall.marshaller.Marshaller
getParser, getSerializer, read, read, readArrayRecords, readRecords, readTokens, write, writeArrayRecords, writeRecords, writeTokens
-
Field Details
-
SERIALIZER
-
PARSER
-
DEFAULT
Default marshaller instance.
-
-
Constructor Details
-
JsonPatchMarshaller
public JsonPatchMarshaller()Creates using the pre-wiredSERIALIZERandPARSER. -
JsonPatchMarshaller
Creates with custom serializer and parser.Callers overriding these should preserve the
.typePropertyName(JsonPatchOperation.class, "op") configuration (and, on the serializer side,.addBeanTypes() /.addRootType() ) or polymorphic dispatch across theJsonPatchOperationsubclasses will not round-trip correctly.- Parameters:
s- The serializer.p- The parser.
-
-
Method Details
-
of
Serializes a POJO to aString using theDEFAULTmarshaller.A shortcut for calling
.DEFAULT .write(object )- Parameters:
object- The object to serialize.- Returns:
- The serialized object.
- Throws:
SerializeException- If a problem occurred trying to convert the output.
-
to
Parses an input into the specified object type using theDEFAULTmarshaller.A shortcut for calling
.DEFAULT .read(input ,type )- Type Parameters:
T- The class type of the object being created.- Parameters:
input- The input.type- The object type to create.- Returns:
- The parsed object.
- Throws:
ParseException- Malformed input encountered.
-
to
Parses an input into the specified parameterized object type using theDEFAULTmarshaller.A shortcut for calling
.DEFAULT .read(input ,type ,args )- Type Parameters:
T- The class type of the object to create.- Parameters:
input- The input.type- The object type to create.args- The type arguments of the class if it's a collection or map.- Returns:
- The parsed object.
- Throws:
ParseException- Malformed input encountered.
-
to
Parses the contents of aReaderinto the specified object type using theDEFAULTmarshaller.A shortcut for calling
that catches anyDEFAULT .read(input ,type )IOExceptionfrom the underlying stream and rethrows it as an uncheckedParseException, so the caller is not burdened with a checked exception.- Type Parameters:
T- The class type of the object being created.- Parameters:
input- The input reader.type- The object type to create.- Returns:
- The parsed object.
- Throws:
ParseException- Malformed input encountered or an I/O error occurred on the underlying stream.
-
to
Parses the contents of aReaderinto the specified parameterized object type using theDEFAULTmarshaller.A shortcut for calling
that catches anyDEFAULT .read(input ,type ,args )IOExceptionfrom the underlying stream and rethrows it as an uncheckedParseException, so the caller is not burdened with a checked exception.- Type Parameters:
T- The class type of the object to create.- Parameters:
input- The input reader.type- The object type to create.args- The type arguments of the class if it's a collection or map.- Returns:
- The parsed object.
- Throws:
ParseException- Malformed input encountered or an I/O error occurred on the underlying stream.
-
of
Serializes a POJO to the specifiedWriterusing theDEFAULTmarshaller.A shortcut for calling
that catches anyDEFAULT .write(object ,output )IOExceptionfrom the underlying stream and rethrows it as an uncheckedSerializeException, so the caller is not burdened with a checked exception.- Parameters:
object- The object to serialize.output- The writer to serialize to.- Throws:
SerializeException- If a problem occurred trying to convert the output or an I/O error occurred on the underlying stream.
-