Class ResponseFactoryRegistry
java.lang.Object
io.github.grumpystuff.grumpyjson.registry.Sealable
io.github.grumpystuff.grumpyrest.response.ResponseFactoryRegistry
Allows to register
ResponseFactorys that provide Response implementations for the response values
returned by handlers.
This class does not extend Registry because it does not work with keys reported by its registrables (i.e.
response factories), but directly calls all factories and uses the first non-null result.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all response factories from this registry.createResponse(RequestCycle requestCycle, Object value) Converts a response value to aResponseusing an appropriate response factory from this registry.protected voidonSeal()voidregister(ResponseFactory factory) Registers a response factory to this registry, to be used when converting a response value to aResponse.Methods inherited from class io.github.grumpystuff.grumpyjson.registry.Sealable
ensureConfigurationPhase, ensureRunTimePhase, seal
-
Constructor Details
-
ResponseFactoryRegistry
public ResponseFactoryRegistry()Constructor. This constructor does not register any factories, but theRestApicalling this constructor does.
-
-
Method Details
-
clear
public void clear()Removes all response factories from this registry. This is useful because the registry that is used by a newly createdRestApicontains default response factories, and the code using it might not want to use them. -
register
Registers a response factory to this registry, to be used when converting a response value to aResponse.- Parameters:
factory- the response factory to register
-
onSeal
protected void onSeal() -
createResponse
Converts a response value to aResponseusing an appropriate response factory from this registry. If multiple response factories support conversion of that value, then the one registered later takes precedence.- Parameters:
requestCycle- the request cycle to create a response for. This is passed in case the response factory wants to do special stuff like look into request properties.value- the response value to convert to aResponse- Returns:
- the response
-