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
Modifier and TypeFieldDescriptionprotected final int
The maximum amount of bytes to buffer.static final int
The default buffer limit before bailing on trying to setContent-Length
.static final MediaType
The default media type is "text/html; charset=UTF-8
".Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger
-
Constructor Summary
ModifierConstructorDescriptionJStachioHttpMessageConverter
(JStachio jstachio) Create http converter from jstachioprotected
JStachioHttpMessageConverter
(JStachio jstachio, MediaType mediaType, int bufferLimit) Creates a message converter with media type and buffer limit. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected Output.CloseableEncodedOutput<IOException>
createOutput
(HttpOutputMessage message) Create the buffered output to use when executing JStachio.protected Object
readInternal
(Class<? extends Object> clazz, HttpInputMessage inputMessage) protected boolean
protected void
writeInternal
(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, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
supports
in classAbstractHttpMessageConverter<Object>
-
canRead
- Specified by:
canRead
in interfaceHttpMessageConverter<Object>
- Overrides:
canRead
in classAbstractHttpMessageConverter<Object>
-
readInternal
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException - Specified by:
readInternal
in classAbstractHttpMessageConverter<Object>
- Throws:
IOException
HttpMessageNotReadableException
-
writeInternal
protected void writeInternal(Object t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException - Specified by:
writeInternal
in classAbstractHttpMessageConverter<Object>
- Throws:
IOException
HttpMessageNotWritableException
-
createOutput
Create the buffered output to use when executing JStachio.- Parameters:
message
- response.- Returns:
- the output ready for writing to.
- See Also:
-