Skip to content

RFC: VertxGen as data object

Julien Viet edited this page Jan 27, 2020 · 3 revisions

VertxGen as data object

Intro

In Vert.x 3, @VertxGen and @DataObject are two separate kind of objects. Some @VertxGen annotated object represent data such as Buffer, MultiMap or SocketAddress.

Allowing such types to be convertible to JSON would enable:

  • using them in DataObject (converter generation would handle them)
  • allow usage in service proxies

Proposed changes

Codegen

Transform DataObjectTypeInfo type to DataObjectInfo, this class is not anymore part of the TypeInfo hierarchy and instead becomes a field of ClassTypeInfo.

@DataObject annotated interfaces providing a static fromJson method are recognised as equivalent of the JsonObject constructor in @DataObject classes.

@DataObject toJson and fromJson method can define any JSON type (i.e JsonObject, String, etc...).

Generators

Update the service proxy and data object generators to handle such types.

Buffer

Buffer currently defines a toJson() method that has a different meaning than the one of this proposal. It will do a best effort to parse the content and return an appropriate object, i.e it will map the 1 string to 1 integer, etc...

Proposal is to provide a new mapToJson() method that does the same and use toJson() to encode the buffer to B64:

  1. toJson() becomes mapToJson()
  2. toJsonObject() becomes mapToJsonObject()
  3. toJsonArray() becomes mapToJsonArray()
  4. toJson() returns java.lang.String and perform B64 conversion
  5. fromJson(String s) transforms a B64 encoded string to a buffer

1+2+3 will also be handled in Vert.x 3.x as part of the deprecation cycle.

MultiMap

Annotated as @DataObject

SocketAddress

Annotated as @DataObject

Clone this wiki locally