TableSchema.converterForAttribute() returns wrong generic type
- Lingua principale
- Java
- Stelle
- 2.6k
- Fork
- 1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 51
Descrizione
### Describe the bug
The `TableSchema` interface has a method, `converterForAttribute(Object key)`, which returns an `AttributeConverter`. This AttributeConverter is meant to convert the attribute behind the given key. Unfortunately, the generic type here (`T`) is the type for the table record, not for the attribute.
If I have the following DynamoDbBean (non-compilable, just for explanation purposes):
```java
@DynamoDbBean
public class ShoppingCartItem{
public static final String CUSTOMER_ID_SECONDARY_INDEX_NAME = "shopping_cart_item_by_customer_id";
private UUID customerId;
@DynamoDbSecondaryPartitionKey(indexNames = CUSTOMER_ID_SECONDARY_INDEX_NAME)
public UUID getCustomerId() {
return customerId;
}
}
```
If then create a corresponding `DynamoDbTable` and try fetching the converter for the secondary partition key:
```java
DynamoDbTable table = ...;
String partitionKey = table.tableSchema().tableMetadata().indexPartitionKey(ShoppingCartItem.CUSTOMER_ID_SECONDARY_INDEX_NAME);
AttributeConverter converter = table.tableSchema().converterForAttribute(partitionKey);
```
The `AttributeConverter` returned is of type `AttributeConverter` instead of type `AttributeConverter`. This makes it impossible to use the TableSchema to fetch the corresponding AttributeConverter, because it will always return an AttributeConverter scoped to the type of the table, not of the attribute.
### Expected Behavior
`TableSchema.converterForAttribute(Object key)` should return a generic type other than `AttributeConverter` so callers can use it properly.
### Current Behavior
Described above.
### Reproduction Steps
Described above.
### Possible Solution
Change the return type of `TableSchema.converterForAttribute(Object key)`.
### Additional Information/Context
_No response_
### AWS Java SDK version used
dynamodb-enhanced-2.20.56
### JDK version used
1.8
### Operating System and version
macOS 13.3.1
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia dal punto di ingresso TableSchema.converterForAttribute(Object key) e traccia la relativa dichiarazione, le implementazioni e i chiamanti nel modulo enhanced DynamoDB. Verifica il contratto generico usando l’esempio ShoppingCartItem: una chiave di partizione secondaria supportata da UUID dovrebbe fornire un AttributeConverter senza compromettere gli altri utenti di TableSchema.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- aws, java
- Ambito
- backend-api-design, databases
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100