java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
io.jstach.opt.spring.web.JStachioHttpMessageConverter
- All Implemented Interfaces:
HttpMessageConverter<Object>
- Direct Known Subclasses:
ServletJStachioHttpMessageConverter
Type-safe way to use JStachio in Spring Web.
For this to work the controllers need to return JStache models and have the controller
method return annotated with ResponseBody.
Example:
@JStache
public record HelloModel(String message){}
@GetMapping(value = "/")
@ResponseBody
public HelloModel hello() {
return new HelloModel("Spring Boot is now JStachioed!");
}
Because JStachio by default pre-encodes the static text parts of the
template the output strategy handles the buffering instead of the framework (usually
servlet) to improve performance and to reliable set Content-Length. This
can be changed by overriding createOutput(HttpOutputMessage).- Author:
- agentgt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe maximum amount of bytes to buffer.static final intThe default buffer limit before bailing on trying to setContent-Length.static final MediaTypeThe default media type is "text/html; charset=UTF-8".Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionJStachioHttpMessageConverter(JStachio jstachio) Create http converter from jstachioprotectedJStachioHttpMessageConverter(JStachio jstachio, MediaType mediaType, int bufferLimit) Creates a message converter with media type and buffer limit. -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected Output.CloseableEncodedOutput<IOException>createOutput(HttpOutputMessage message) Create the buffered output to use when executing JStachio.protected ObjectreadInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) protected booleanprotected voidwriteInternal(Object t, HttpOutputMessage outputMessage) Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, supportsRepeatableWrites, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.converter.HttpMessageConverter
getSupportedMediaTypes
-
Field Details
-
DEFAULT_MEDIA_TYPE
The default media type is "text/html; charset=UTF-8". -
DEFAULT_BUFFER_LIMIT
The default buffer limit before bailing on trying to setContent-Length. The default is "65536".- See Also:
-
bufferLimit
The maximum amount of bytes to buffer.
-
-
Constructor Details
-
JStachioHttpMessageConverter
Create http converter from jstachio- Parameters:
jstachio- an instance usually created by spring
-
JStachioHttpMessageConverter
Creates a message converter with media type and buffer limit.- Parameters:
jstachio- an instance usually created by springmediaType- used to set ContentTypebufferLimit- buffer limit before bailing on trying to setContent-Length.
-
-
Method Details
-
supports
- Specified by:
supportsin classAbstractHttpMessageConverter<Object>
-
canRead
- Specified by:
canReadin interfaceHttpMessageConverter<Object>- Overrides:
canReadin classAbstractHttpMessageConverter<Object>
-
readInternal
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException - Specified by:
readInternalin classAbstractHttpMessageConverter<Object>- Throws:
IOExceptionHttpMessageNotReadableException
-
writeInternal
protected void writeInternal(Object t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException - Specified by:
writeInternalin classAbstractHttpMessageConverter<Object>- Throws:
IOExceptionHttpMessageNotWritableException
-
createOutput
Create the buffered output to use when executing JStachio.- Parameters:
message- response.- Returns:
- the output ready for writing to.
- See Also:
-