Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with lombok #250

Open
hauter opened this issue Apr 23, 2019 · 4 comments
Open

Not compatible with lombok #250

hauter opened this issue Apr 23, 2019 · 4 comments

Comments

@hauter
Copy link

hauter commented Apr 23, 2019

This is a code example in the book (guide-for-java-devs.pdf), and I made a piece of changes.

  1. Wiki.java corresponds with the database table:
@AllArgsConstructor
public class Wiki {
    public Long id;
    public String name;
}
  1. WikiDbService.java
@ProxyGen
public interface WikiDbService {

    @Fluent
    WikiDbService fetchAll(Handler<AsyncResult<JsonArray>> resultHandler);

    @GenIgnore
    static WikiDbService create(JDBCClient dbClient, Handler<AsyncResult<WikiDbService>> readyHandler) {
        return new WikiDbServiceImpl(dbClient, readyHandler);
    }

    @GenIgnore
    static WikiDbService createProxy(Vertx vertx, String address) {
        return new WikiDbServiceVertxEBProxy(vertx, address);
    }
}
  1. WikiDbServiceImpl.java
    @Override
    public WikiDbService fetchAll(Handler<AsyncResult<JsonArray>> resultHandler) {
        dbClient.query(FETCH_ALL_SQL, queryAr -> {
            if (queryAr.failed()) {
                resultHandler.handle(Future.failedFuture(queryAr.cause()));
                return;
            }

            ResultSet resultSet = queryAr.result();
            List<Wiki> wikiList = resultSet.getResults().stream()
                .map(r -> new Wiki(r.getLong(0), r.getString(1)))
                .collect(Collectors.toList());

            resultHandler.handle(Future.succeededFuture(new JsonArray(new Gson().toJson(wikiList))));
        });

        return this;
    }

Finally, I got a compilation error:

image

it means that there no suitable constructor for Wiki class with 2 arguments ....

But If I generate the constructor:

public class Wiki {
    public Long id;
    public String name;

    public Wiki(Long id, String name) {
        this.id = id;
        this.name = name;
    }
}

It works.

So I think it's not compatible with lombok ...

@adityaLath18
Copy link

Did you get any solution for using codegen and lombok both?

@vietj
Copy link
Member

vietj commented Jan 20, 2021

does lombok works with code generators ?

@hbayrousson
Copy link

Hi,

With the step-3 in the book (guide-for-java-devs.pdf), and your changes, and some changes, I have an compilation success and the code is generated correctly.

My changes are :

  • upgrade to vertx 4.0.0

  • Adding this in the pom.xml :
    <annotationProcessors> <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor> <annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor> </annotationProcessors>

Moreover, if I add in the wiki class :

package io.vertx.guides.wiki.database;
import io.vertx.codegen.annotations.DataObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@Setter
@AllArgsConstructor
@DataObject(generateConverter = true)
  public class Wiki {
    public Long id;
    public String name;
  }

After compiling, I have this file generated :

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package io.vertx.guides.wiki.database;

import io.vertx.core.json.JsonObject;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class WikiConverter {
    public WikiConverter() {
    }

    public static void fromJson(Iterable<Entry<String, Object>> json, Wiki obj) {
        Iterator var2 = json.iterator();

        while(var2.hasNext()) {
            Entry<String, Object> member = (Entry)var2.next();
            String var4 = (String)member.getKey();
            byte var5 = -1;
            switch(var4.hashCode()) {
            case 3355:
                if (var4.equals("id")) {
                    var5 = 0;
                }
                break;
            case 3373707:
                if (var4.equals("name")) {
                    var5 = 1;
                }
            }

            switch(var5) {
            case 0:
                if (member.getValue() instanceof Number) {
                    obj.setId(((Number)member.getValue()).longValue());
                }
                break;
            case 1:
                if (member.getValue() instanceof String) {
                    obj.setName((String)member.getValue());
                }
            }
        }

    }

    public static void toJson(Wiki obj, JsonObject json) {
        toJson(obj, json.getMap());
    }

    public static void toJson(Wiki obj, Map<String, Object> json) {
        if (obj.getId() != null) {
            json.put("id", obj.getId());
        }

        if (obj.getName() != null) {
            json.put("name", obj.getName());
        }

    }
}

@jbaris
Copy link

jbaris commented Jul 29, 2021

Thank you @hbayrousson. Adding:
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants