vert.x
vert.x copied to clipboard
SerializableCodec breaks on internal classes
The class SerializableCodec
is able to send a serializable POJO over the eventbus.
If the class contains e.g. a JsonObject
however, it breaks as those classes does not implement Serializable.
To me it sounds feasible to support this. What do you think? Or should it just be the fact that you need to rely on Map etc for this?
A small example of a class:
public class MyPojo implements Serializable {
public String first;
public String second;
public JsonObject json;
}
The error in its relevant length is this, for completeness:
java.lang.RuntimeException: java.io.NotSerializableException: io.vertx.core.json.JsonObject
at io.vertx.core.impl.SerializableUtils.toBytes(SerializableUtils.java:24)
at io.vertx.core.eventbus.impl.codecs.SerializableCodec.transform(SerializableCodec.java:48)
at io.vertx.core.eventbus.impl.MessageImpl.<init>(MessageImpl.java:65)
at io.vertx.core.eventbus.impl.MessageImpl.copyBeforeReceive(MessageImpl.java:71)
at io.vertx.core.eventbus.impl.EventBusImpl.deliverMessageLocally(EventBusImpl.java:364)
at io.vertx.core.eventbus.impl.EventBusImpl.sendLocally(EventBusImpl.java:341)
at io.vertx.core.eventbus.impl.EventBusImpl.sendOrPub(EventBusImpl.java:329)
at io.vertx.core.eventbus.impl.OutboundDeliveryContext.execute(OutboundDeliveryContext.java:109)
at io.vertx.core.eventbus.impl.DeliveryContextBase.next(DeliveryContextBase.java:72)
at io.vertx.core.eventbus.impl.OutboundDeliveryContext.next(OutboundDeliveryContext.java:28)
at io.vertx.core.eventbus.impl.EventBusImpl.sendOrPubInternal(EventBusImpl.java:422)
at io.vertx.core.eventbus.impl.EventBusImpl.sendOrPubInternal(EventBusImpl.java:428)
at io.vertx.core.eventbus.impl.EventBusImpl.request(EventBusImpl.java:127)
at io.vertx.core.eventbus.EventBus.request(EventBus.java:92)
maybe we should rollback the serializable codec or make JsonObject serializable.
I don't think we should rollback the serializable codec.
We could make a few vert.x API classes serializable but then:
- we must carefully define a small list of candidates (I'd say at most
JsonObject
,JsonArray
,Buffer
) - we need to take into account generated apis if applicable (e.g. Rx or Mutiny
Buffer
)
But for the moment @thced , you should customize serialization for the few classes where you embed JSON
I agree with @tsegismont ; the implementation is nice, and there are ways around, such as using a map instead of JsonObject. But it would be a nice feature I think.
that's the reason i was a bit reluctant to allow serializable, because this now implies that we need to use more serializable in vertx and I fear it might propagate again to unknow unknown classes at the moment.
No plans to further enhance Serializable
integration.