Class SerializedHeader

java.lang.Object
org.apache.juneau.http.classic.header.BasicHeader
org.apache.juneau.http.classic.header.SerializedHeader
All Implemented Interfaces:
Serializable, Header, NameValuePair

public class SerializedHeader extends BasicHeader
  • Constructor Details

    • SerializedHeader

      public SerializedHeader(String name, Object value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty)
      Constructor.
      Parameters:
      name - The HTTP header name name.
      value - The POJO to serialize to the parameter value. Can be null. The effect is implementation-dependent — see HttpPartSerializerSession and HttpPartSchema.
      serializer - The serializer to use for serializing the value to a string value.
      Can be null, in which case the value is converted directly to a string instead of being serialized.
      schema - The schema object that defines the format of the output.
      If null, defaults to the schema defined on the serializer.
      If that's also null, defaults to HttpPartSchema.DEFAULT.
      Only used if serializer is schema-aware (e.g. OpenApiSerializer).
      Can also be a Supplier.
      skipIfEmpty - If value is a blank string, the value should return as null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • SerializedHeader

      public SerializedHeader(String name, Supplier<Object> value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty)
      Constructor with delayed value.

      Header value is re-evaluated on each call to getValue().

      Parameters:
      name - The HTTP header name name.
      value - The supplier of the POJO to serialize to the parameter value. Can be null. The effect is implementation-dependent — see HttpPartSerializerSession and HttpPartSchema.
      serializer - The serializer to use for serializing the value to a string value.
      Can be null, in which case the value is converted directly to a string instead of being serialized.
      schema - The schema object that defines the format of the output.
      If null, defaults to the schema defined on the serializer.
      If that's also null, defaults to HttpPartSchema.DEFAULT.
      Only used if serializer is schema-aware (e.g. OpenApiSerializer).
      Can also be a Supplier.
      skipIfEmpty - If value is a blank string, the value should return as null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • SerializedHeader

      protected SerializedHeader(SerializedHeader copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The object to copy. Must not be null or a NullPointerException is thrown.
  • Method Details

    • of

      public static SerializedHeader of(String name, Object value)
      Static creator.
      Parameters:
      name - The header name.
      value - The POJO to serialize as the header value.
      Can be null. The effect is implementation-dependent — see HttpPartSerializerSession and HttpPartSchema.
      Returns:
      A new header bean. Never null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static SerializedHeader of(String name, Object value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty)
      Static creator.
      Parameters:
      name - The HTTP header name name.
      value - The POJO to serialize as the header value.
      serializer - The serializer to use for serializing the value to a string value.
      Can be null, in which case the value is converted directly to a string instead of being serialized.
      schema - The schema object that defines the format of the output.
      If null, defaults to the schema defined on the serializer.
      If that's also null, defaults to HttpPartSchema.DEFAULT.
      Only used if serializer is schema-aware (e.g. OpenApiSerializer).
      Can also be a Supplier.
      skipIfEmpty - If value is a blank string, the value should return as null.
      Returns:
      A new header bean. Never null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static SerializedHeader of(String name, Supplier<?> value)
      Static creator with delayed value.

      Header value is re-evaluated on each call to getValue().

      Parameters:
      name - The header name.
      value - The supplier of the POJO to serialize as the header value.
      Can be null. The effect is implementation-dependent — see HttpPartSerializerSession and HttpPartSchema.
      Returns:
      A new header bean. Never null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static SerializedHeader of(String name, Supplier<?> value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty)
      Static creator with delayed value.

      Header value is re-evaluated on each call to getValue().

      Parameters:
      name - The HTTP header name name.
      value - The supplier of the POJO to serialize as the header value.
      serializer - The serializer to use for serializing the value to a string value.
      Can be null, in which case the value is converted directly to a string instead of being serialized.
      schema - The schema object that defines the format of the output.
      If null, defaults to the schema defined on the serializer.
      If that's also null, defaults to HttpPartSchema.DEFAULT.
      Only used if serializer is schema-aware (e.g. OpenApiSerializer).
      Can also be a Supplier.
      skipIfEmpty - If value is a blank string, the value should return as null.
      Returns:
      A new header bean. Never null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • copy

      Creates a copy of this object.
      Overrides:
      copy in class BasicHeader
      Returns:
      A new copy of this object.
    • copyWith

      Copies this bean and sets the serializer and schema on it.
      Parameters:
      serializer - The new serializer for the bean. Can be null to leave the serializer unchanged.
      schema - The new schema for the bean. Can be null to leave the schema unchanged.
      Returns:
      Either a new bean with the serializer set, or this bean if both values are null or the serializer and schema were already set.
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
      Overrides:
      getValue in class BasicHeader
    • schema

      Sets the schema object that defines the format of the output.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • serializer

      Sets the serializer to use for serializing the value to a string value.
      Parameters:
      value - The new value for this property. Can be null (no-op).
      Returns:
      This object.
    • serializer

      Sets the serializer to use for serializing the value to a string value.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • skipIfEmpty

      Don't serialize this header if the value is null or an empty string.
      Returns:
      This object.
    • skipIfEmpty

      public SerializedHeader skipIfEmpty(boolean value)
      Don't serialize this header if the value is null or an empty string.
      Parameters:
      value - The new value of this setting.
      Returns:
      This object.