Interface JsonMessage

All Known Subinterfaces:
ConnectionDetails, TelestionConfiguration
All Known Implementing Classes:
ConnectionData, DecodedMessage, DefaultConfigVerticle.Configuration, GenericConfiguration, NoConfiguration, PingVerticle.Configuration, PongVerticle.Configuration, Position, Positions, Publisher.Configuration, RawMessage, Receiver.Configuration, Requester.Configuration, Responder.Configuration, SayHello.Configuration, Sender.Configuration, SenderData, SerialConn.Configuration, SerialData, SerialDetails, SimpleCommand, SimpleCommandHandler.Configuration, SimpleMessage, StaticSender.Configuration, TcpClient.Configuration, TcpConn.Data, TcpConn.Participant, TcpData, TcpDetails, TcpDispatcher.Configuration, TcpServer.Configuration, TestVerticle.Configuration, UdpDetails, UntypedConfiguration

public interface JsonMessage

Description

The base class for all messages which are automatically encoded with the JsonMessageCodec.

All subclasses have to be valid json classes. This means that they could be encoded by JsonCodec which is backed by JacksonCodec.

Usage

 
 public record TimeMessage(
     @JsonProperty long receiveTime,
     @JsonProperty long sendTime
 ) implements JsonMessage {
 }
 
 
  • Field Details

    • logger

      static final org.slf4j.Logger logger
  • Method Details

    • on

      static <T extends JsonMessage> boolean on(Class<T> type, io.vertx.core.buffer.Buffer json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)
      Asynchronous version of from(Buffer, Class).
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      type - the class of the target JsonMessage
      json - the buffer whose contents contain the necessary information to construct the specified JsonMessage
      handler - gets called when the conversion was successful
      exceptionHandler - gets called when a DecodeException occurred during conversion
      Returns:
      true when the conversion was successful
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, String json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)
      Asynchronous version of from(String, Class).
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      type - the class of the target JsonMessage
      json - the JSON String that contains the necessary information to construct the specified JsonMessage
      handler - gets called when the conversion was successful
      exceptionHandler - gets called when a DecodeException or an IllegalArgumentException occurred during conversion
      Returns:
      true when the conversion was successful
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, Object json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)
      Asynchronous version of from(Object, Class).
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      type - the class of the target JsonMessage
      json - the plain Object that contains the necessary information to construct the specified JsonMessage
      handler - gets called when the conversion was successful
      exceptionHandler - gets called when a DecodeException or an IllegalArgumentException occurred during conversion
      Returns:
      true when the conversion was successful
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, io.vertx.core.eventbus.Message<?> message, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)
      Asynchronous version of from(Message, Class).
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      type - the class of the target JsonMessage
      message - the message whose body contains the necessary information to construct the specified JsonMessage
      handler - gets called when the conversion was successful
      exceptionHandler - gets called when a DecodeException or an IllegalArgumentException occurred during conversion
      Returns:
      true when the conversion was successful
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, io.vertx.core.buffer.Buffer json, io.vertx.core.Handler<T> handler)
      Like on(Class, Buffer, Handler, Handler) but without an exception handler.
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, String json, io.vertx.core.Handler<T> handler)
      Like on(Class, String, Handler, Handler) but without an exception handler.
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, Object json, io.vertx.core.Handler<T> handler)
      Like on(Class, Object, Handler, Handler) but without an exception handler.
    • on

      static <T extends JsonMessage> boolean on(Class<T> type, io.vertx.core.eventbus.Message<?> message, io.vertx.core.Handler<T> handler)
      Like on(Class, Message, Handler, Handler) but without an exception handler.
    • on

      static <T extends JsonMessage> io.vertx.core.Future<T> on(Class<T> type, io.vertx.core.buffer.Buffer json)
      Like on(Class, Buffer, Handler, Handler) but returns a Future which resolves when the conversion completes successfully or fails when a DecodeException or an IllegalArgumentException occurs during conversion.
      Returns:
      a future that represents the conversion state
    • on

      static <T extends JsonMessage> io.vertx.core.Future<T> on(Class<T> type, String json)
      Like on(Class, String, Handler, Handler) but returns a Future which resolves when the conversion completes successfully or fails when a DecodeException or an IllegalArgumentException occurs during conversion.
      Returns:
      a future that represents the conversion state
    • on

      static <T extends JsonMessage> io.vertx.core.Future<T> on(Class<T> type, Object json)
      Like on(Class, Object, Handler, Handler) but returns a Future which resolves when the conversion completes successfully or fails when a DecodeException or an IllegalArgumentException occurs during conversion.
      Returns:
      a future that represents the conversion state
    • on

      static <T extends JsonMessage> io.vertx.core.Future<T> on(Class<T> type, io.vertx.core.eventbus.Message<?> message)
      Like on(Class, Message, Handler, Handler) but returns a Future which resolves when the conversion completes successfully or fails when a DecodeException occurs during conversion.
      Returns:
      a future that represents the conversion state
    • from

      static <T extends JsonMessage> T from(io.vertx.core.buffer.Buffer json, Class<T> type) throws io.vertx.core.json.DecodeException
      Constructs a JsonMessage from a buffer which contains an encoded JSON string.
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      json - the buffer that contents contain the necessary information to construct the specified JsonMessage
      type - the class of the target JsonMessage
      Returns:
      the decoded message
      Throws:
      io.vertx.core.json.DecodeException - if the buffer contents does not contain the necessary information to successfully construct the specified JsonMessage
    • from

      static <T extends JsonMessage> T from(String json, Class<T> type) throws io.vertx.core.json.DecodeException
      Constructs a JsonMessage from a JSON String.
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      json - the JSON String that contains the necessary information to construct the specified JsonMessage
      type - the class of the target JsonMessage
      Returns:
      the decoded message
      Throws:
      io.vertx.core.json.DecodeException - if the JSON string does not contain the necessary information to successfully construct the specified JsonMessage
    • from

      static <T extends JsonMessage> T from(Object json, Class<T> type) throws io.vertx.core.json.DecodeException
      Constructs a JsonMessage from a plain Object.
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      json - the plain Object that contains the necessary information to construct the specified JsonMessage
      type - the class of the target JsonMessage
      Returns:
      the decoded message
      Throws:
      io.vertx.core.json.DecodeException - if the plain object does not contain the necessary information to successfully construct the specified JsonMessage
    • from

      static <T extends JsonMessage> T from(io.vertx.core.eventbus.Message<?> message, Class<T> type) throws io.vertx.core.json.DecodeException
      Constructs a JsonMessage from a Vert.x EventBus Message body.
      Type Parameters:
      T - the type of the target JsonMessage
      Parameters:
      message - the message which body contains the necessary information to construct the specified JsonMessage
      type - the class of the target JsonMessage
      Returns:
      the decoded message
      Throws:
      io.vertx.core.json.DecodeException - if the raw message body does not contain the necessary information to successfully construct the specified JsonMessage
    • json

      @Deprecated(since="0.9.0") default io.vertx.core.json.JsonObject json() throws IllegalArgumentException
      Deprecated.
      Use toJsonObject() to get a JSON object representation of this message or use toJsonString() to get a JSON string.
      Throws:
      IllegalArgumentException
    • toJsonObject

      default io.vertx.core.json.JsonObject toJsonObject() throws IllegalArgumentException
      Constructs a JsonObject from the JsonMessage.
      Returns:
      the constructed JSON object
      Throws:
      IllegalArgumentException - if the JSON object cannot represent the type of any JsonMessage property
    • toJsonString

      default String toJsonString(boolean pretty) throws io.vertx.core.json.EncodeException
      Constructs a String containing the properties of the JsonMessage as JSON values.
      Parameters:
      pretty - if true the JSON output is properly formatted
      Returns:
      a JSON string representing the JsonMessage
      Throws:
      io.vertx.core.json.EncodeException - if the JsonMessage containing properties that cannot be represented by JSON values
      See Also:
      JacksonCodec.toString(Object, boolean)
    • toJsonString

      default String toJsonString() throws io.vertx.core.json.EncodeException
      Like toJsonString(boolean) but with space efficient JSON output.
      Throws:
      io.vertx.core.json.EncodeException
    • toJsonBuffer

      default io.vertx.core.buffer.Buffer toJsonBuffer(boolean pretty) throws io.vertx.core.json.EncodeException
      Constructs a Buffer containing the properties of the JsonMessage as JSON values
      Parameters:
      pretty - if true the JSON output is properly formatted
      Returns:
      a buffer representing the JsonMessage
      Throws:
      io.vertx.core.json.EncodeException - if the JsonMessage containing properties that cannot be represented by JSON values
      See Also:
      JacksonCodec.toBuffer(Object, boolean)
    • toJsonBuffer

      default io.vertx.core.buffer.Buffer toJsonBuffer() throws io.vertx.core.json.EncodeException
      Like toJsonBuffer(boolean) but with space efficient JSON output.
      Throws:
      io.vertx.core.json.EncodeException
    • className

      default String className()
      Returns the simple class name of the implementing subclass.
      Returns:
      simple class name of subclass