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 String
Returns the simple class name of the implementing subclass.static <T extends JsonMessage>
TConstructs aJsonMessage
from a buffer which contains an encoded JSON string.static <T extends JsonMessage>
TConstructs aJsonMessage
from a Vert.x EventBusMessage
body.static <T extends JsonMessage>
TConstructs aJsonMessage
from a plainObject
.static <T extends JsonMessage>
TConstructs aJsonMessage
from a JSONString
.default io.vertx.core.json.JsonObject
json()
Deprecated.static <T extends JsonMessage>
io.vertx.core.Future<T>Likeon(Class, Buffer, Handler, Handler)
but returns aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
occurs 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 aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
occurs 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 aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
occurs 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 aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
occurs 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.Buffer
LiketoJsonBuffer(boolean)
but with space efficient JSON output.default io.vertx.core.buffer.Buffer
toJsonBuffer(boolean pretty)
Constructs aBuffer
containing the properties of theJsonMessage
as JSON valuesdefault io.vertx.core.json.JsonObject
Constructs aJsonObject
from theJsonMessage
.default String
LiketoJsonString(boolean)
but with space efficient JSON output.default String
toJsonString(boolean pretty)
Constructs aString
containing the properties of theJsonMessage
as 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 targetJsonMessage
json
- the buffer whose contents contain the necessary information to construct the specifiedJsonMessage
handler
- gets called when the conversion was successfulexceptionHandler
- gets called when aDecodeException
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 offrom(String, Class)
.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
type
- the class of the targetJsonMessage
json
- the JSONString
that contains the necessary information to construct the specifiedJsonMessage
handler
- gets called when the conversion was successfulexceptionHandler
- gets called when aDecodeException
or anIllegalArgumentException
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 offrom(Object, Class)
.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
type
- the class of the targetJsonMessage
json
- the plainObject
that contains the necessary information to construct the specifiedJsonMessage
handler
- gets called when the conversion was successfulexceptionHandler
- gets called when aDecodeException
or anIllegalArgumentException
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 offrom(Message, Class)
.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
type
- the class of the targetJsonMessage
message
- the message whose body contains the necessary information to construct the specifiedJsonMessage
handler
- gets called when the conversion was successfulexceptionHandler
- gets called when aDecodeException
or anIllegalArgumentException
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)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 aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
occurs during conversion.- Returns:
- a future that represents the conversion state
-
on
Likeon(Class, String, Handler, Handler)
but returns aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
occurs during conversion.- Returns:
- a future that represents the conversion state
-
on
Likeon(Class, Object, Handler, Handler)
but returns aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
or anIllegalArgumentException
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)Likeon(Class, Message, Handler, Handler)
but returns aFuture
which resolves when the conversion completes successfully or fails when aDecodeException
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.DecodeExceptionConstructs aJsonMessage
from 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 specifiedJsonMessage
type
- 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 aJsonMessage
from a JSONString
.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
json
- the JSONString
that contains the necessary information to construct the specifiedJsonMessage
type
- 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 aJsonMessage
from a plainObject
.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
json
- the plainObject
that contains the necessary information to construct the specifiedJsonMessage
type
- 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 aJsonMessage
from a Vert.x EventBusMessage
body.- Type Parameters:
T
- the type of the targetJsonMessage
- Parameters:
message
- the message which body contains the necessary information to construct the specifiedJsonMessage
type
- 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 aJsonObject
from theJsonMessage
.- Returns:
- the constructed JSON object
- Throws:
IllegalArgumentException
- if the JSON object cannot represent the type of anyJsonMessage
property
-
toJsonString
Constructs aString
containing the properties of theJsonMessage
as JSON values.- Parameters:
pretty
- iftrue
the JSON output is properly formatted- Returns:
- a JSON string representing the
JsonMessage
- Throws:
io.vertx.core.json.EncodeException
- if theJsonMessage
containing 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 aBuffer
containing the properties of theJsonMessage
as JSON values- Parameters:
pretty
- iftrue
the JSON output is properly formatted- Returns:
- a buffer representing the
JsonMessage
- Throws:
io.vertx.core.json.EncodeException
- if theJsonMessage
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.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.