Class AbstractPayloadNodeBuilder<T extends AbstractPayloadNodeBuilder<T>>

java.lang.Object
net.ygbstudio.powerwp4j.base.extension.builders.AbstractPayloadNodeBuilder<T>
Type Parameters:
T - The type of the concrete builder subclass.
Direct Known Subclasses:
WPMediaPayloadNodeBuilder, WPPayloadNodeBuilder

public abstract class AbstractPayloadNodeBuilder<T extends AbstractPayloadNodeBuilder<T>> extends Object
Abstract base class for payload builders based on 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

    Fields
    Modifier and Type
    Field
    Description
    protected tools.jackson.databind.node.ObjectNode
    Backing JSON object used to assemble the payload.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an empty payload node builder base.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <E extends FriendlyEnum>
    T
    add(E propertyEnum, boolean value)
    Adds a property with the given propertyEnum value and boolean value to the payload node.
    protected <E extends FriendlyEnum>
    T
    add(E propertyEnum, int value)
    Adds a property with the given propertyEnum value and int value to the payload node.
    protected <E extends FriendlyEnum>
    T
    add(E propertyEnum, long value)
    Adds a property with the given propertyEnum value and long value to the payload node.
    protected <E extends FriendlyEnum>
    T
    add(E propertyEnum, short value)
    Adds a property with the given propertyEnum value and short value to the payload node.
    protected <E extends CacheKeyEnum>
    T
    add(E propertyEnum, String value)
    Adds a property with the given propertyEnum value and value to the payload node.
    protected T
    add(String propertyName, boolean value)
    Adds a property with the specified name and boolean value to the payload node.
    protected T
    add(String propertyName, int value)
    Adds a property with the specified name and int value to the payload node.
    protected T
    add(String propertyName, long value)
    Adds a property with the specified name and long value to the payload node.
    protected T
    add(String propertyName, short value)
    Adds a property with the specified name and short value to the payload node.
    protected T
    add(String propertyName, String value)
    Adds a property with the specified name and value to the payload node.
    protected <E extends FriendlyEnum>
    T
    add(@NotNull CacheKeyEnum propertyEnum, E value)
    Adds a property with the given propertyEnum value and a value enum to the payload node.
    protected T
    add(@NotNull FriendlyEnum propertyEnum, @NotNull Collection<? extends Number> valueArray)
    Adds an integer array property with the specified propertyEnum value and int value array to the payload node.
    tools.jackson.databind.JsonNode
    Builds the payload node object as a JSON node.
    Clears the payload node object, resetting it to an empty object.
    protected tools.jackson.databind.node.ObjectNode
    Returns the payload node object used to build the JSON payload.
    protected T
    Returns the current instance of the payload builder.
    protected void
    setPayloadNode(tools.jackson.databind.node.ObjectNode payloadNode)
    Sets the payload node object used to build the JSON payload.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • payloadNode

      protected tools.jackson.databind.node.ObjectNode payloadNode
      Backing JSON object used to assemble the payload.
  • Constructor Details

    • AbstractPayloadNodeBuilder

      protected AbstractPayloadNodeBuilder()
      Creates an empty payload node builder base.
  • Method Details

    • self

      protected T 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

      protected T add(String propertyName, String value)
      Adds a property with the specified name and value to the payload node.
      Parameters:
      propertyName - the name of the property
      value - the value of the property
      Returns:
      the current instance of the payload builder
    • add

      protected T add(String propertyName, long value)
      Adds a property with the specified name and long value to the payload node.
      Parameters:
      propertyName - the name of the property
      value - the long value of the property
      Returns:
      the current instance of the payload builder
    • add

      protected T add(String propertyName, int value)
      Adds a property with the specified name and int value to the payload node.
      Parameters:
      propertyName - the name of the property
      value - the int value of the property
      Returns:
      the current instance of the payload builder
    • add

      protected T add(String propertyName, short value)
      Adds a property with the specified name and short value to the payload node.
      Parameters:
      propertyName - the name of the property
      value - the short value of the property
      Returns:
      the current instance of the payload builder
    • add

      protected T add(String propertyName, boolean value)
      Adds a property with the specified name and boolean value to the payload node.
      Parameters:
      propertyName - the name of the property
      value - the boolean value of the property
      Returns:
      the current instance of the payload builder
    • add

      protected <E extends CacheKeyEnum> T add(@NotNull E propertyEnum, String value)
      Adds a property with the given propertyEnum value and value to the payload node.
      Type Parameters:
      E - the enum type for the property key
      Parameters:
      propertyEnum - the enum value of the property
      value - 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 given propertyEnum value and a value enum to the payload node.
      Type Parameters:
      E - the enum type for the value
      Parameters:
      propertyEnum - the enum value of the property
      value - the value enum of the property
      Returns:
      the current instance of the payload builder
    • add

      protected <E extends FriendlyEnum> T add(@NotNull E propertyEnum, int value)
      Adds a property with the given propertyEnum value and int value to the payload node.
      Type Parameters:
      E - the enum type for the property key
      Parameters:
      propertyEnum - the enum value of the property
      value - the value of the property (int)
      Returns:
      the current instance of the payload builder
    • add

      protected <E extends FriendlyEnum> T add(@NotNull E propertyEnum, long value)
      Adds a property with the given propertyEnum value and long value to the payload node.
      Type Parameters:
      E - the enum type for the property key
      Parameters:
      propertyEnum - the enum value of the property
      value - the value of the property (long)
      Returns:
      the current instance of the payload builder
    • add

      protected <E extends FriendlyEnum> T add(@NotNull E propertyEnum, short value)
      Adds a property with the given propertyEnum value and short value to the payload node.
      Type Parameters:
      E - the enum type for the property key
      Parameters:
      propertyEnum - the enum value of the property
      value - the value of the property (short)
      Returns:
      the current instance of the payload builder
    • add

      protected <E extends FriendlyEnum> T add(@NotNull E propertyEnum, boolean value)
      Adds a property with the given propertyEnum value and boolean value to the payload node.
      Type Parameters:
      E - the enum type for the property key
      Parameters:
      propertyEnum - the enum value of the property
      value - 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 specified propertyEnum value and int value array to the payload node. In order for a collection to be added, its wildcard will be captured as part of the following Number subtypes:

      Integer, Long or Short.

      Parameters:
      propertyEnum - the enum value of the property
      valueArray - the value array of the property (int)
      Returns:
      the current instance of the payload builder
    • clear

      public T 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