Class SerializedPart

java.lang.Object
org.apache.juneau.http.part.BasicPart
org.apache.juneau.http.part.SerializedPart
All Implemented Interfaces:
NameValuePair, Headerable

public class SerializedPart extends BasicPart implements Headerable
Subclass of NameValuePair for serializing POJOs as URL-encoded form post entries using the class.
Example:

NameValuePairs params = new NameValuePairs() .append(new SerializedNameValuePair("myPojo", pojo, UrlEncodingSerializer.DEFAULT_SIMPLE)) .append(new BasicNameValuePair("someOtherParam", "foobar")); request.setEntity(new UrlEncodedFormEntity(params));

See Also:
  • Constructor Details

    • SerializedPart

      public SerializedPart(String name, Object value, HttpPartType type, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty)
      Constructor.
      Parameters:
      name - The part name.
      value - The POJO to serialize to The part value.
      type - The HTTP part type.
      serializer - The serializer to use for serializing the value to a string value.
      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).
      skipIfEmpty - If value is a blank string, the value should return as null.
    • SerializedPart

      protected SerializedPart(SerializedPart copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The object to copy.
  • Method Details

    • of

      public static SerializedPart of(String name, Object value)
      Instantiates a new instance of this object.
      Parameters:
      name - The part name.
      value - The part value.
      Can be any POJO.
      Returns:
      A new SerializedPart object, never null.
    • of

      public static SerializedPart of(String name, Supplier<?> value)
      Instantiates a new instance of this object.
      Parameters:
      name - The part name.
      value - The part value supplier.
      Can be a supplier of any POJO.
      Returns:
      A new SerializedPart object, never null.
    • copy

      public SerializedPart copy()
      Creates a copy of this object.
      Returns:
      A new copy of this object.
    • type

      Sets the HTTP part type.
      Parameters:
      value - The new value for this 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.
      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.
      Returns:
      This object.
    • schema

      Sets the schema object that defines the format of the output.
      Parameters:
      value - The new value for this property.
      Returns:
      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.
      schema - The new schema for the bean. Can be null.
      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.
    • skipIfEmpty

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

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

      Description copied from interface: Headerable
      Convert the object to a Header.
      Specified by:
      asHeader in interface Headerable
      Overrides:
      asHeader in class BasicPart
      Returns:
      The object converted to a Header.
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
      Overrides:
      getValue in class BasicPart