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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault StringReturns the simple class name of the implementing subclass.static <T extends JsonMessage>
TConstructs aJsonMessagefrom a buffer which contains an encoded JSON string.static <T extends JsonMessage>
TConstructs aJsonMessagefrom a Vert.x EventBusMessagebody.static <T extends JsonMessage>
TConstructs aJsonMessagefrom a plainObject.static <T extends JsonMessage>
TConstructs aJsonMessagefrom a JSONString.default io.vertx.core.json.JsonObjectjson()Deprecated.static <T extends JsonMessage>
io.vertx.core.Future<T>Likeon(Class, Buffer, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs during conversion.static <T extends JsonMessage>
booleanLikeon(Class, Buffer, Handler, Handler)but without an exception handler.static <T extends JsonMessage>
booleanon(Class<T> type, io.vertx.core.buffer.Buffer json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)Asynchronous version offrom(Buffer, Class).static <T extends JsonMessage>
io.vertx.core.Future<T>Likeon(Class, Message, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionoccurs during conversion.static <T extends JsonMessage>
booleanLikeon(Class, Message, Handler, Handler)but without an exception handler.static <T extends JsonMessage>
booleanon(Class<T> type, io.vertx.core.eventbus.Message<?> message, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)Asynchronous version offrom(Message, Class).static <T extends JsonMessage>
io.vertx.core.Future<T>Likeon(Class, Object, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs during conversion.static <T extends JsonMessage>
booleanLikeon(Class, Object, Handler, Handler)but without an exception handler.static <T extends JsonMessage>
booleanon(Class<T> type, Object json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)Asynchronous version offrom(Object, Class).static <T extends JsonMessage>
io.vertx.core.Future<T>Likeon(Class, String, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs during conversion.static <T extends JsonMessage>
booleanLikeon(Class, String, Handler, Handler)but without an exception handler.static <T extends JsonMessage>
booleanon(Class<T> type, String json, io.vertx.core.Handler<T> handler, io.vertx.core.Handler<RuntimeException> exceptionHandler)Asynchronous version offrom(String, Class).default io.vertx.core.buffer.BufferLiketoJsonBuffer(boolean)but with space efficient JSON output.default io.vertx.core.buffer.BuffertoJsonBuffer(boolean pretty)Constructs aBuffercontaining the properties of theJsonMessageas JSON valuesdefault io.vertx.core.json.JsonObjectConstructs aJsonObjectfrom theJsonMessage.default StringLiketoJsonString(boolean)but with space efficient JSON output.default StringtoJsonString(boolean pretty)Constructs aStringcontaining the properties of theJsonMessageas JSON values.
-
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 offrom(Buffer, Class).- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
type- the class of the targetJsonMessagejson- the buffer whose contents contain the necessary information to construct the specifiedJsonMessagehandler- gets called when the conversion was successfulexceptionHandler- gets called when aDecodeExceptionoccurred during conversion- Returns:
truewhen 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 offrom(String, Class).- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
type- the class of the targetJsonMessagejson- the JSONStringthat contains the necessary information to construct the specifiedJsonMessagehandler- gets called when the conversion was successfulexceptionHandler- gets called when aDecodeExceptionor anIllegalArgumentExceptionoccurred during conversion- Returns:
truewhen 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 offrom(Object, Class).- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
type- the class of the targetJsonMessagejson- the plainObjectthat contains the necessary information to construct the specifiedJsonMessagehandler- gets called when the conversion was successfulexceptionHandler- gets called when aDecodeExceptionor anIllegalArgumentExceptionoccurred during conversion- Returns:
truewhen 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 offrom(Message, Class).- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
type- the class of the targetJsonMessagemessage- the message whose body contains the necessary information to construct the specifiedJsonMessagehandler- gets called when the conversion was successfulexceptionHandler- gets called when aDecodeExceptionor anIllegalArgumentExceptionoccurred during conversion- Returns:
truewhen 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)Likeon(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)Likeon(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)Likeon(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)Likeon(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)Likeon(Class, Buffer, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs during conversion.- Returns:
- a future that represents the conversion state
-
on
Likeon(Class, String, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs during conversion.- Returns:
- a future that represents the conversion state
-
on
Likeon(Class, Object, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionor anIllegalArgumentExceptionoccurs 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)Likeon(Class, Message, Handler, Handler)but returns aFuturewhich resolves when the conversion completes successfully or fails when aDecodeExceptionoccurs 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.DecodeExceptionConstructs aJsonMessagefrom a buffer which contains an encoded JSON string.- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
json- the buffer that contents contain the necessary information to construct the specifiedJsonMessagetype- the class of the targetJsonMessage- Returns:
- the decoded message
- Throws:
io.vertx.core.json.DecodeException- if the buffer contents does not contain the necessary information to successfully construct the specifiedJsonMessage
-
from
static <T extends JsonMessage> T from(String json, Class<T> type) throws io.vertx.core.json.DecodeExceptionConstructs aJsonMessagefrom a JSONString.- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
json- the JSONStringthat contains the necessary information to construct the specifiedJsonMessagetype- the class of the targetJsonMessage- Returns:
- the decoded message
- Throws:
io.vertx.core.json.DecodeException- if the JSON string does not contain the necessary information to successfully construct the specifiedJsonMessage
-
from
static <T extends JsonMessage> T from(Object json, Class<T> type) throws io.vertx.core.json.DecodeExceptionConstructs aJsonMessagefrom a plainObject.- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
json- the plainObjectthat contains the necessary information to construct the specifiedJsonMessagetype- the class of the targetJsonMessage- Returns:
- the decoded message
- Throws:
io.vertx.core.json.DecodeException- if the plain object does not contain the necessary information to successfully construct the specifiedJsonMessage
-
from
static <T extends JsonMessage> T from(io.vertx.core.eventbus.Message<?> message, Class<T> type) throws io.vertx.core.json.DecodeExceptionConstructs aJsonMessagefrom a Vert.x EventBusMessagebody.- Type Parameters:
T- the type of the targetJsonMessage- Parameters:
message- the message which body contains the necessary information to construct the specifiedJsonMessagetype- the class of the targetJsonMessage- 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 specifiedJsonMessage
-
json
@Deprecated(since="0.9.0") default io.vertx.core.json.JsonObject json() throws IllegalArgumentExceptionDeprecated.UsetoJsonObject()to get a JSON object representation of this message or usetoJsonString()to get a JSON string.- Throws:
IllegalArgumentException
-
toJsonObject
Constructs aJsonObjectfrom theJsonMessage.- Returns:
- the constructed JSON object
- Throws:
IllegalArgumentException- if the JSON object cannot represent the type of anyJsonMessageproperty
-
toJsonString
Constructs aStringcontaining the properties of theJsonMessageas JSON values.- Parameters:
pretty- iftruethe JSON output is properly formatted- Returns:
- a JSON string representing the
JsonMessage - Throws:
io.vertx.core.json.EncodeException- if theJsonMessagecontaining properties that cannot be represented by JSON values- See Also:
JacksonCodec.toString(Object, boolean)
-
toJsonString
LiketoJsonString(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.EncodeExceptionConstructs aBuffercontaining the properties of theJsonMessageas JSON values- Parameters:
pretty- iftruethe JSON output is properly formatted- Returns:
- a buffer representing the
JsonMessage - Throws:
io.vertx.core.json.EncodeException- if theJsonMessagecontaining 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.EncodeExceptionLiketoJsonBuffer(boolean)but with space efficient JSON output.- Throws:
io.vertx.core.json.EncodeException
-
className
Returns the simple class name of the implementing subclass.- Returns:
- simple class name of subclass
-
toJsonObject()to get a JSON object representation of this message or usetoJsonString()to get a JSON string.