Interface RepresentationFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Representation) from
response model maps.
Typically, plugins will provide one implementation of this interface for each different response model template used
by the plugin.
The mapping of the template name to the implementation class is done on the
CanSupportHaapi descriptor interface, implemented by any
plugin that supports HAAPI.
The apply(RepresentationModel, RepresentationFactory) method will only be called if
the response is successful.
If this function is also used to render an error-scoped response model, it should also implement the
applyError(ErrorRepresentationModel, ProblemRepresentationFactory) method to create the error
representation. If it doesn't, or if it returns Optional.empty(), then a generic error representation will be
automatically generated using the response model.
- Since:
- 5.4.0
-
Method Summary
Modifier and TypeMethodDescriptionapply(RepresentationModel model, RepresentationFactory factory) Produces a representation from a success response model.default Optional<? extends Representation>applyError(ErrorRepresentationModel representationModel, ProblemRepresentationFactory factory) Produces a representation from an error response model.
-
Method Details
-
apply
Produces a representation from a success response model.If this function should never be used to create a successful
Representation, this method may return null or, to be more explicit, throwUnsupportedOperationException.- Parameters:
model- The response model defined by the handler. (seeResponse.setResponseModel(ResponseModel, Response.ResponseModelScope))factory- An object with multiple factory methods to create different types of representation.- Returns:
- A representation of the response model map.
-
applyError
default Optional<? extends Representation> applyError(ErrorRepresentationModel representationModel, ProblemRepresentationFactory factory) Produces a representation from an error response model.- Parameters:
representationModel- The response model defined by the handler. (seeResponse.setResponseModel(ResponseModel, Response.ResponseModelScope))factory- An object with multiple factory methods to create different types of representation.- Returns:
- A representation of the response model map. If
Optional.empty()is returned, the default error function is used instead.
-