Not compatible with lombok
This is a code example in the book (guide-for-java-devs.pdf), and I made a piece of changes.
-
Wiki.javacorresponds with the database table:
@AllArgsConstructor
public class Wiki {
public Long id;
public String name;
}
-
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);
}
}
-
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:

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 ...
Did you get any solution for using codegen and lombok both?
does lombok works with code generators ?
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());
}
}
}
Thank you @hbayrousson. Adding:
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
did the trick.