Closed pgressa closed 3 years ago
Ok so the issue with cart is now in redis. It's on our side in CartItem..
{“message”:“Error decoding HTTP response body: Error decoding stream for type [interface java.util.List]: Cannot set final field: api.services.CartsService$CartItem.id. Enable by specifying \“allowWrite\” for this field in the reflection configuration.\n at [Source: (byte[])\“[{\“id\“:\“b0f83f31-f7db-4163-9d97-08b307508881\“,\“itemId\“:\“MU-US-004\“,\“quantity\“:2,\“unitPrice\“:4.989999771118164},{\“id\“:\“968def63-6af3-4295-b791-983caadbabf6\“,\“itemId\“:\“MU-US-003\“,\“quantity\“:2,\“unitPrice\“:7.989999771118164},{\“id\“:\“e28244c7-f492-4689-abd5-22a915a8b89b\“,\“itemId\“:\“MU-US-002\“,\“quantity\“:2,\“unitPrice\“:28.989999771118164},{\“id\“:\“c07c7e87-84be-4174-b839-4d837e0a02f1\“,\“itemId\“:\“MU-US-005\“,\“quantity\“:1,\“unitPrice\“:9.5},{\“id\“:\“8055e351-d195-40d0-bf3a-fd11728dc3e4\“,\“itemId\“:\“MU-US-001\“,\“quant\“[truncated 25 bytes]; line: 1, column: 8] (through reference chain: java.util.ArrayList[0]->api.services.CartsService$CartItem[\“id\“])“,”_links”:{“self”:{“href”:“/api/cart”,“templated”:false}}}
this is the error message from the browser not from the application log, that's why we were missing it
The problematic code is this one:
@Schema(title = "Cart item")
@Introspected
static class CartItem {
private final String id;
private String itemId;
private final int quantity;
private BigDecimal unitPrice;
public CartItem() {
id = UUID.randomUUID().toString();
quantity = 1;
}
/**
* Item id.
*/
public String getId() {
return id;
}
/**
* Item name.
*/
public String getItemId() {
return itemId;
}
/**
* Item quantity.
*/
public int getQuantity() {
return quantity;
}
/**
* Item unit price.
*/
public BigDecimal getUnitPrice() {
return unitPrice;
}
}
And I'm interested in: a) How come it works in JIT and not in native image? Maybe we're missing something in @introspected? b) How come it's not in app log! That message should have been with stack trace somewhere
@graemerocher maybe this can lead us to some missing things in Micronaut in general?
So it looks like in JIT mode Jackson uses reflection to fallback to writing the id
etc. which is final
but this is not supported in native image and since the CartItem
has no constructor annotated with @Creator
to deserialise the problem occurs.
As for the missing logs that is mystery, we need to track down if the logs would be missing for JIT mode as well.
@graemerocher I'll try to break the cart id deserialisation so it will generate some error.
Blocked by release of micronaut-security that contains https://github.com/micronaut-projects/micronaut-security/commit/a97adb893cb33c8be76f0dbb8a64c3183448a1dd
Fixes #86