vertx-codegen icon indicating copy to clipboard operation
vertx-codegen copied to clipboard

DataObject: Generate a converter for java records

Open vatevr opened this issue 4 years ago • 11 comments

Hi,

This issue proposes to support java16 records with @DataObject generator. Atm generated converter @DataObject for java16 records is empty.

@DataObject(generateConverter = true)
public record Page(int limit, int skip) {
    public Page(JsonObject json) {}
    public JsonObject toJson() {}
}

vatevr avatar Aug 19 '21 09:08 vatevr

as we will soon support Java 17, I guess we could have some code doing this using multi version jar ?

vietj avatar Aug 19 '21 12:08 vietj

I'm not assigning a version for now

vietj avatar Aug 19 '21 12:08 vietj

Hi, is it possible to make constructor and toJson() methods as optional? If anyone ​wants to override default serialization/deserialization they could define custom conversion logic. Now for simple data objects it is required to write all repetitive and error prone conversions

deedarb avatar Mar 02 '22 11:03 deedarb

Any update on this @vietj?

thced avatar May 23 '22 07:05 thced

not yet @thced

vietj avatar May 23 '22 08:05 vietj

is help still needed with this ? id be willing to help out if someone can point me in the right direction as to where the changes are needed in order to support records... @vietj

I can see that we might need to add the record element kind right here public boolean process() { if (!processed) { if (modelElt.getKind() == ElementKind.INTERFACE || modelElt.getKind() == ElementKind.CLASS) {

and prob some more stuff in pom to support ElemenKind.RECORD

Reef3rm4n avatar May 27 '22 09:05 Reef3rm4n

Is there any change this will worked on soon? Would you accept a PR for this?

runtarinn avatar Mar 17 '23 13:03 runtarinn

I think the main issue is that records are only available in Java 14 and vertx 4 depends on Java 8, we could try suppporting it as a separate project that would be java 14 exclusive

vietj avatar Mar 17 '23 15:03 vietj

I think the main issue is that records are only available in Java 14 and vertx 4 depends on Java 8, we could try suppporting it as a separate project that would be java 14 exclusive

What do you think about the branch 5.x to be java 17+ compatible instead of 11?

cvgaviao avatar Apr 23 '23 18:04 cvgaviao

@vietj are there any further developments on java upgrade?

vatevr avatar Mar 27 '24 10:03 vatevr

nothing has changed, perhaps we can try to have something compatible with data objects as well using tricks and testing with the right java version, I don't know the amount of changes that would be needed for that

vietj avatar Mar 27 '24 10:03 vietj