vert-x3 / vertx-service-proxy

EventBus Proxy generation
Apache License 2.0
67 stars 58 forks source link

Support Type Variable in Interface #74

Closed sherl0cks closed 6 years ago

sherl0cks commented 6 years ago

I'd like to do something similar to what I can do with Spring Data, where I can declare an interface with generics and then extend that interface with the appropriate type information and vert.x service proxies has the smarts to generate the appropriate information behind the scenes

For example, I'd like to use the following code without rewriting the same interface for every repository, which I anticipate to have several:


public interface Repository<T extends Aggregate> {
    void load(String aggregateIdentifier, Handler<AsyncResult<T>> resultHandler);

    void save(T aggregate, Handler<AsyncResult<Void>> resultHandler);
}

@ProxyGen
public interface DriverRepository extends Repository<Driver> {
}

public interface Aggregate {
    String identifier();
}

@DataObject(generateConverter = true)
public class Driver implements Aggregate {

    private String id;

    public Driver(JsonObject jsonObject) {
    }

    public Driver(String id) {
        this.id = id;
    }

    protected Driver() {
    }

    @Override
    public String identifier() {
        return id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public JsonObject toJson() {
        JsonObject json = new JsonObject();
        return json;
    }
}
vietj commented 6 years ago

have you tried ?

vietj commented 6 years ago

I believe it should kind of work

vietj commented 6 years ago

I'm not saying it should work, but codegen, I believe it should be possible to support this

sherl0cks commented 6 years ago

@vietj yeap I have tried, I seem to be hitting this exception https://github.com/vert-x3/vertx-codegen/blob/master/src/main/java/io/vertx/codegen/ClassModel.java#L601

vietj commented 6 years ago

I think it should be support if the base repository class is not annotated with @VertxGen.

can you open an issue on the codegen project with this reproducer ?

it would be great to support such common pattern when building code generated interfaces.

vietj commented 6 years ago

closing this issue