Description
Document values for the anyDocument data type can have any of the four document formats (binary, JSON, text, or XML).
When calling a Data Service endpoint with a parameter having the anyDocument data type, the caller must specify the format of each document value so the Java API can set the Content Type header that communicates the format of the document value to the appserver.
Similarly, when a Data Service endpoint returns document values with the anyDocument data type, the appserver must communicate the format of the document value to the Java API. The appserver sets the Content Type header for the document value. In turn, the Java API must set the equivalent format when returning the document value to the caller.
In both cases, the Java API associates a document value with a format by wrapping the document value with a handle, which has a getter and setter for the format. In particular, the document value are represented with any subclass that implements the BufferableContentHandle interface (which includes most of the out-of-the-box handles provided by the Java API). Additional considerations:
When generating a Data Service interface using the Gradle plugin provided by the ml-development-tools, the $javaClass annotation for an anyDocument type can specify a BufferableContentHandle subclass. If no $javaClass is provided, the default is InputStreamHandle. (An invalid $javaClass annotation throws an error at the start of code generation.)
The predefined IO Data Service classes (InputCaller, OutputCaller, and InputOutputCaller) must also be able to support anyDocument for either input or output. These classes can each add a static factory that takes handles for the input and / or output similar to:
static <IC,IR,OC,OR> InputOutputCaller<BufferableContentHandle<IC,IR>,BufferableContentHandle<OC,OR>> onHandles(
DatabaseClient client, JSONWriteHandle apiDecl,
BufferableContentHandle<IC,IR> inputHandle, BufferableContentHandle<OC,OR> outputHandle
) {
return new InputOutputEndpointImpl<>(client, apiDecl, new HandleProvider.DirectHandleProvider<>(inputHandle, outputHandle));
}