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
@Json annotations are ignored on Immutables objects #2066
Comments
Thank you for filing an issue with the JDBI project. Do you happen to have a test case or some sample code for us to look at? |
@hgschmie do you have a project template where I can insert example configs? Summary, if we have an Immutables type like this @Value.Immutable
public interface Cart {
static Builder builder() {
return ImmutableCart.builder();
}
@Json //this annotation is not detected because Jdbi reflects on the ImmutableCart
// workaround is available by using the InjectJdbiJson annotation below
CartedProduct getProduct();
interface Builder {
// this property is processed by BuilderPojoProperties.createProperty so even if a workaround for getProduct is used,
// this property is unaware of the Json annotation put on the getter above
Builder product(Product product);
Cart build();
}
} Then this repository doesn't work public interface CartRepository {
@SqlUpdate("insert into carts(product) values (:product)")
//because it can't find an argument factory
void create(@BindBean Cart cart);
@SqlQuery("select product from cart limit 1")
//because it can't find a mapper
Optional<Cart> findOne();
} |
There is a workaround for update queries / argument mappers using InjectAnnotation from Immutables. But it only allows to set the @JSON annotation on the getter, not on the builder mutator @InjectAnnotation(type = Json.class, target = ACCESSOR)
public @interface InjectJdbiJson {} |
I spent a few minutes trying to put a test together but I am not sure. I don't know where "CartedProduct" comes etc. There are some examples for bean mapping in the test classes; it would be very useful to have some example on how you use immutables (and ideally working code with the workaround that breaks when removing it). |
After some time trying to make Json work with Immutables and debugging Jdbi it looks like if we map an Immutable object to arguments
@Json
is discarded and because of that the standard Json argument factory doesn't handle the typeThe text was updated successfully, but these errors were encountered: