Class AbstractPayloadNodeBuilder<T extends AbstractPayloadNodeBuilder<T>>
- Type Parameters:
T- The type of the concrete builder subclass.
- Direct Known Subclasses:
WPMediaPayloadNodeBuilder,WPPayloadNodeBuilder
ObjectNode.
This class provides common functionality for building payload nodes used in the WordPress REST
API. It implements the builder pattern and provides methods to set various properties of the
payload node. It serves as an alternative to AbstractPayloadBuilder or the media payload
builder AbstractMediaPayloadBuilder class and offers a different, low-level approach to
payload creation by using a centralized ObjectNode, making it even easier to create
specialized builders with specific boundaries.
AbstractPayloadNodeBuilder was created to allow for extra fields that are not part of
the WordPress default payload. For example, if you have custom fields/keys, you can implement a
payload builder that allows you to work effortlessly with those fields. In theory, you can do
that with AbstractPayloadBuilder and extend it, however, if you want to implement a
payload builder that suits your needs more and does not give you default fields, this one is a
good alternative.
An implementation of builders following this abstract class will be provided in the
net.ygbstudio.powerwp4j.builders package to demonstrate its suggested usage.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected tools.jackson.databind.node.ObjectNodeBacking JSON object used to assemble the payload. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an empty payload node builder base. -
Method Summary
Modifier and TypeMethodDescriptionprotected <E extends FriendlyEnum>
Tadd(E propertyEnum, boolean value) Adds a property with the givenpropertyEnumvalue andbooleanvalue to the payload node.protected <E extends FriendlyEnum>
Tadd(E propertyEnum, int value) Adds a property with the givenpropertyEnumvalue andintvalue to the payload node.protected <E extends FriendlyEnum>
Tadd(E propertyEnum, long value) Adds a property with the givenpropertyEnumvalue andlongvalue to the payload node.protected <E extends FriendlyEnum>
Tadd(E propertyEnum, short value) Adds a property with the givenpropertyEnumvalue andshortvalue to the payload node.protected <E extends CacheKeyEnum>
TAdds a property with the givenpropertyEnumvalue andvalueto the payload node.protected TAdds a property with the specified name and boolean value to the payload node.protected TAdds a property with the specified name and int value to the payload node.protected TAdds a property with the specified name and long value to the payload node.protected TAdds a property with the specified name and short value to the payload node.protected TAdds a property with the specified name and value to the payload node.protected <E extends FriendlyEnum>
Tadd(@NotNull CacheKeyEnum propertyEnum, E value) Adds a property with the givenpropertyEnumvalue and avalueenum to the payload node.protected Tadd(@NotNull FriendlyEnum propertyEnum, @NotNull Collection<? extends Number> valueArray) Adds an integer array property with the specifiedpropertyEnumvalue andintvalue array to the payload node.tools.jackson.databind.JsonNodebuild()Builds the payload node object as a JSON node.clear()Clears the payload node object, resetting it to an empty object.protected tools.jackson.databind.node.ObjectNodeReturns the payload node object used to build the JSON payload.protected Tself()Returns the current instance of the payload builder.protected voidsetPayloadNode(tools.jackson.databind.node.ObjectNode payloadNode) Sets the payload node object used to build the JSON payload.
-
Field Details
-
payloadNode
protected tools.jackson.databind.node.ObjectNode payloadNodeBacking JSON object used to assemble the payload.
-
-
Constructor Details
-
AbstractPayloadNodeBuilder
protected AbstractPayloadNodeBuilder()Creates an empty payload node builder base.
-
-
Method Details
-
self
Returns the current instance of the payload builder. This is a protected method used for chaining method calls.The cast to type T is safe because the method is only called within the class hierarchy and this class is parameterized with the type of the subclass.
- Returns:
- the current instance of the payload builder
-
getPayloadNode
protected tools.jackson.databind.node.ObjectNode getPayloadNode()Returns the payload node object used to build the JSON payload.- Returns:
- the payload node object
-
setPayloadNode
protected void setPayloadNode(tools.jackson.databind.node.ObjectNode payloadNode) Sets the payload node object used to build the JSON payload.- Parameters:
payloadNode- the payload node object to set
-
add
Adds a property with the specified name and value to the payload node.- Parameters:
propertyName- the name of the propertyvalue- the value of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the specified name and long value to the payload node.- Parameters:
propertyName- the name of the propertyvalue- the long value of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the specified name and int value to the payload node.- Parameters:
propertyName- the name of the propertyvalue- the int value of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the specified name and short value to the payload node.- Parameters:
propertyName- the name of the propertyvalue- the short value of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the specified name and boolean value to the payload node.- Parameters:
propertyName- the name of the propertyvalue- the boolean value of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the givenpropertyEnumvalue andvalueto the payload node.- Type Parameters:
E- the enum type for the property key- Parameters:
propertyEnum- the enum value of the propertyvalue- the value of the property- Returns:
- the current instance of the payload builder
-
add
protected <E extends FriendlyEnum> T add(@NotNull @NotNull CacheKeyEnum propertyEnum, @NotNull E value) Adds a property with the givenpropertyEnumvalue and avalueenum to the payload node.- Type Parameters:
E- the enum type for the value- Parameters:
propertyEnum- the enum value of the propertyvalue- the value enum of the property- Returns:
- the current instance of the payload builder
-
add
Adds a property with the givenpropertyEnumvalue andintvalue to the payload node.- Type Parameters:
E- the enum type for the property key- Parameters:
propertyEnum- the enum value of the propertyvalue- the value of the property (int)- Returns:
- the current instance of the payload builder
-
add
Adds a property with the givenpropertyEnumvalue andlongvalue to the payload node.- Type Parameters:
E- the enum type for the property key- Parameters:
propertyEnum- the enum value of the propertyvalue- the value of the property (long)- Returns:
- the current instance of the payload builder
-
add
Adds a property with the givenpropertyEnumvalue andshortvalue to the payload node.- Type Parameters:
E- the enum type for the property key- Parameters:
propertyEnum- the enum value of the propertyvalue- the value of the property (short)- Returns:
- the current instance of the payload builder
-
add
Adds a property with the givenpropertyEnumvalue andbooleanvalue to the payload node.- Type Parameters:
E- the enum type for the property key- Parameters:
propertyEnum- the enum value of the propertyvalue- the value of the property (boolean)- Returns:
- the current instance of the payload builder
-
add
protected T add(@NotNull @NotNull FriendlyEnum propertyEnum, @NotNull @NotNull Collection<? extends Number> valueArray) Adds an integer array property with the specifiedpropertyEnumvalue andintvalue array to the payload node. In order for a collection to be added, its wildcard will be captured as part of the followingNumbersubtypes:- Parameters:
propertyEnum- the enum value of the propertyvalueArray- the value array of the property (int)- Returns:
- the current instance of the payload builder
-
clear
Clears the payload node object, resetting it to an empty object.- Returns:
- the current instance of the payload builder
-
build
public tools.jackson.databind.JsonNode build()Builds the payload node object as a JSON node.- Returns:
- the JSON node representing the payload node object
-