vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

SerializableCodec breaks on internal classes

Open thced opened this issue 1 year ago • 4 comments

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)

thced avatar Jul 08 '22 09:07 thced

maybe we should rollback the serializable codec or make JsonObject serializable.

vietj avatar Jul 08 '22 12:07 vietj

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

tsegismont avatar Jul 08 '22 13:07 tsegismont

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.

thced avatar Jul 08 '22 13:07 thced

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.

vietj avatar Jul 11 '22 07:07 vietj

No plans to further enhance Serializable integration.

tsegismont avatar Nov 18 '22 13:11 tsegismont