Skip to main content

@Content

The @Content annotation can be applied to arguments of @RemoteOp-annotated methods to denote that they are the HTTP body of the request.

Contentschema
Examples
// Used on parameter
@Remote(path="/petstore")
public interface PetStore {

@RemotePost("/pets")
String addPet(@Content Pet pet);
}
// Used on class
@Remote(path="/petstore")
public interface PetStore {

@RemotePost("/pets")
String addPet(Pet pet);
}

@Content
public class Pet {...}

The argument can be any of the following types:

  • Any serializable POJO - Converted to output using the Serializer registered with the RestClient. Content-Type is set to that of the Serializer.
  • Reader - Raw contents of Reader will be serialized to remote resource. Content-Type is set to text/plain.
  • InputStream - Raw contents of InputStream will be serialized to remote resource. Content-Type is set to application/octet-stream.
  • PartList - Converted to a URL-encoded FORM post. Content-Type is set to application/x-www-form-urlencoded.
  • HttpEntity - Bypass Juneau serialization and pass HttpEntity directly to HttpClient.

OpenAPI schema based serialization can be used by using the OpenApiSerializer class.

@RemotePost("/comma-delimited-pipe-delimited-ints")
String addCommaDelimitedPipeDelimitedInts(
@Content(
serializer=OpenApiSerializer.class,
schema=@Schema(
type="array",
collectionFormat="pipes",
items=@Items(
type="array"
items=@SubItems(
type="int32",
// Auto-validates on client side!
minimum="0",
maximum="64"
)
)
)
)
int[][] input
);
// Same as above but using free-form schema.
// Format is simplified-JSON (outer {} brackets are optional).
@RemotePost("/comma-delimited-pipe-delimited-ints")
String addCommaDelimitedPipeDelimitedInts(
@Content(
serializer=OpenApiSerializer.class,
schema=@Schema(
"type:'array',collectionFormat:'pipes',items:[type:'array',items:[type:'int32',minimum:0,maximum:64]]"
)
)
int[][] input
);

See OpenAPI Serializers for information about supported data types in OpenAPI serialization. If your RestClient class does not have a serializer associated with it, the body will automatically be serialized to a string using the rules defined in POJO Categories.