-
- All Implemented Interfaces:
-
io.javalin.json.JsonMapper
public final class JavalinJackson implements JsonMapper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
JavalinJackson.Companion
-
Field Summary
Fields Modifier and Type Field Description private final <Error class: unknown class>
mapper
-
Constructor Summary
Constructors Constructor Description JavalinJackson(ObjectMapper objectMapper, Boolean useVirtualThreads)
-
Method Summary
Modifier and Type Method Description final <Error class: unknown class>
getMapper()
String
toJsonString(Object obj, Type type)
Javalin uses this method for io.javalin.http.Context.json, as well as the CookieStore class, WebSockets messaging, and JavalinVue. InputStream
toJsonStream(Object obj, Type type)
Javalin uses this method for io.javalin.http.Context.json, if called with useStreamingMapper = true. Unit
writeToOutputStream(Stream<?> stream, OutputStream outputStream)
Javalin uses this method for io.javalin.http.Context.writeJsonStream. <T extends Any> T
fromJsonString(String json, Type targetType)
If . <T extends Any> T
fromJsonStream(InputStream json, Type targetType)
If implemented, Javalin will use this method instead of . final JavalinJackson
updateMapper(Consumer<ObjectMapper> updateFunction)
Update the current mapper and return self for easy chaining -
-
Constructor Detail
-
JavalinJackson
JavalinJackson(ObjectMapper objectMapper, Boolean useVirtualThreads)
-
-
Method Detail
-
getMapper
final <Error class: unknown class> getMapper()
-
toJsonString
String toJsonString(Object obj, Type type)
Javalin uses this method for io.javalin.http.Context.json, as well as the CookieStore class, WebSockets messaging, and JavalinVue.
-
toJsonStream
InputStream toJsonStream(Object obj, Type type)
Javalin uses this method for io.javalin.http.Context.json, if called with useStreamingMapper = true. When implementing this method, use (or look at) PipedStreamUtil to get an InputStream from an OutputStream.
-
writeToOutputStream
Unit writeToOutputStream(Stream<?> stream, OutputStream outputStream)
Javalin uses this method for io.javalin.http.Context.writeJsonStream. When implementing this method you are expected to consume
stream
one element at a time, convert that element to JSON, and write that element's corresponding JSON to theoutputStream
. The intent is to reduce the amount of memory used during transformation of a data stream to JSON.It is implied that the
stream
of objects will be transformed to an Array type in JSON. In other words, it is your responsibility to surround the output with[
and]
.The
outputStream
will be a compressed output stream.The content type header will already be set to "application/json".
Once Javalin calls this function, it will not participate any further in the response. It becomes your responsibility to deliver the remainder of the response to the
outputStream
.When your implementation returns from this function, assume that the underlying resources for the
stream
will be released.
-
fromJsonString
<T extends Any> T fromJsonString(String json, Type targetType)
If .fromJsonStream is not implemented, Javalin will use this method when mapping request bodies to JSON through io.javalin.http.Context.bodyAsClass. Regardless of if .fromJsonStream is implemented, Javalin will use this method for Validation and for WebSocket messaging.
-
fromJsonStream
<T extends Any> T fromJsonStream(InputStream json, Type targetType)
If implemented, Javalin will use this method instead of .fromJsonString when mapping request bodies to JSON through io.javalin.http.Context.bodyAsClass.
-
updateMapper
final JavalinJackson updateMapper(Consumer<ObjectMapper> updateFunction)
Update the current mapper and return self for easy chaining
-
-
-
-