Class UpdateOrderRequest

java.lang.Object
com.broadleafcommerce.order.web.endpoint.domain.UpdateOrderRequest
All Implemented Interfaces:
Serializable

public class UpdateOrderRequest extends Object implements Serializable
A request DTO used to update a Order.

It is important to note that the combined usage of @Nullable and Optional for the fields is entirely intentional. Since there is no way to distinguish between a value not being supplied and being updated to null, this mechanism is necessary.

If the request JSON does not have a particular field's key, the field in this DTO will deserialize to null. If the request JSON does have the field's key but the value is null, the field in this DTO will deserialize to Optional.empty().

An earlier, alternate implementation relied on a single Map<String, Object> "updateFields" property to achieve the same distinction between unsupplied and null, but this approach had the flaw of not being able to take advantage of Jackson's automatic type-safe deserialization. With the current approach, Jackson can understand the declared types and automatically verify and convert the fields to the appropriate types.

Another important note is that the use of @Data and @Setter with AccessLevel#PRIVATE is intentional. This is required for getting the behavior we want from Jackson on deserialization, while still maintaining @Value-like immutability. If we were to use @Value, Jackson would always set unsupplied keys to Optional.empty(). However, when we use @Data, it seems that Jackson simply does not call the setters for the fields with unsupplied keys, which leaves them null (giving us our desired behavior).

Author:
Dima Myroniuk (dmyroniuk)
See Also:
  • Constructor Details

    • UpdateOrderRequest

      public UpdateOrderRequest()
  • Method Details

    • getOrderId

      public String getOrderId()
      The ID of the order to update.
      Returns:
      the order ID this update is for
    • getName

      @Nullable public Optional<String> getName()
      See Also:
      • Order.getName()
    • getStatus

      @Nullable public Optional<String> getStatus()
      See Also:
      • Order.getStatus()
    • getAttributes

      @Nullable public Optional<Map<String,Object>> getAttributes()
      See Also:
      • Order.getAttributes()
    • getInternalAttributes

      @Nullable public Optional<Map<String,Object>> getInternalAttributes()
      See Also:
      • Order.getInternalAttributes()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setOrderId

      public void setOrderId(String orderId)
      The ID of the order to update.
      Parameters:
      orderId - the order ID this update is for