Open hauter opened 5 years ago
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 :
`
<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.
This is a code example in the book (guide-for-java-devs.pdf), and I made a piece of changes.
Wiki.java
corresponds with the database table:WikiDbService.java
WikiDbServiceImpl.java
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:
It works.
So I think it's not compatible with lombok ...