bloxbean / cardano-client-lib

Cardano client library in Java
https://cardano-client.dev
MIT License
118 stars 49 forks source link

Possible issue in Converter classes for @Constr #436

Open nemo83 opened 1 week ago

nemo83 commented 1 week ago

I'm not sure if I'm doing something wrong, but

Given an interface and two class implementations, one empty class and one class w/ one property (as per MyOptional example) https://github.com/bloxbean/cardano-client-lib/blob/fix/blueprint-sum-type-annotation/annotation-processor/src/test/java/com/bloxbean/cardano/client/plutus/annotation/processor/model/MyOptional.java

The code that is autogenerated has error.

Screenshot 2024-09-13 at 00 20 28
satran004 commented 1 week ago

@nemo83 Currently @Constr annotation can only be applied to a class not interface. So in this case, you need to do something like this.

public interface MyOptional {
}

@Constr
public class Some implements MyOptional {
    private BigInteger value;

    public BigInteger getValue() {
        return value;
    }

    public void setValue(BigInteger value) {
        this.value = value;
    }
}
@Constr(alternative = 1)
public class None implements MyOptional {
}
nemo83 commented 1 week ago

What if you MyOption appears in another model object?

EDIT:

By converting MyOption from interface to abstract class seemed to have done the trick.

Anyway, blueprint seems to be able to handle @Constr at interface level when for example you have a Redeemer which can be something like

pub type Redeemer {
Withdraw,
Spend(something: Int)
}

The auto generated code is already:

@Constr
public interface Redeemer {
}