Interface JsonMapper


  • public interface JsonMapper
    • Method Detail

      • toJsonString

        @NotNull
        default String toJsonString​(@NotNull
                                    Object obj)
        Javalin uses this method for Context.json(Object), as well as the CookieStore class, WebSockets messaging, and JavalinVue.
      • toJsonStream

        @NotNull
        default InputStream toJsonStream​(@NotNull
                                         Object obj)
        Javalin uses this method for Context.json(Object), if called with useStreamingMapper = true. When implementing this method, use (or look at) PipedStreamUtil to get an InputStream from an OutputStream.
      • fromJsonString

        @NotNull
        default <T> T fromJsonString​(@NotNull
                                     String json,
                                     @NotNull
                                     Class<T> targetClass)
        If fromJsonStream(InputStream, Class) is not implemented, Javalin will use this method when mapping request bodies to JSON through Context.bodyAsClass(Class). Regardless of if fromJsonStream(InputStream, Class) is implemented, Javalin will use this method for Validation and for WebSocket messaging.
      • fromJsonStream

        @NotNull
        default <T> T fromJsonStream​(@NotNull
                                     InputStream json,
                                     @NotNull
                                     Class<T> targetClass)
        If implemented, Javalin will use this method instead of fromJsonString(String, Class) when mapping request bodies to JSON through Context.bodyAsClass(Class).