Skip to content

Commit 3093726

Browse files
tsachevAlexandre Dutra
authored andcommitted
JAVA-1464: Allow custom codecs with non public constructors in @Param
1 parent 19e1017 commit 3093726

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [improvement] JAVA-1203: Upgrade Metrics to allow usage in OSGi.
77
- [bug] JAVA-1407: KeyspaceMetadata exportAsString should export user types in topological sort order.
88
- [bug] JAVA-1455: Mapper support using unset for null values.
9+
- [bug] JAVA-1464: Allow custom codecs with non public constructors in @Param.
910

1011

1112
### 3.2.0

driver-mapping/src/main/java/com/datastax/driver/mapping/MethodMapper.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.datastax.driver.mapping;
1717

1818
import com.datastax.driver.core.*;
19+
import com.datastax.driver.mapping.annotations.Defaults;
1920
import com.google.common.collect.Sets;
2021
import com.google.common.reflect.TypeToken;
2122
import com.google.common.util.concurrent.Futures;
@@ -186,14 +187,7 @@ static class ParamMapper {
186187
this.paramName = paramName;
187188
this.paramIdx = paramIdx;
188189
this.paramType = (TypeToken<Object>) paramType;
189-
try {
190-
this.codec = (codecClass == null) ? null : (TypeCodec<Object>) codecClass.newInstance();
191-
} catch (Exception e) {
192-
throw new IllegalArgumentException(String.format(
193-
"Cannot create instance of codec %s for parameter %s",
194-
codecClass, (paramName == null) ? paramIdx : paramName
195-
), e);
196-
}
190+
this.codec = codecClass == null || codecClass.equals(Defaults.NoCodec.class) ? null : (TypeCodec<Object>) ReflectionUtils.newInstance(codecClass);
197191
}
198192

199193
void setValue(BoundStatement boundStatement, Object arg) {

0 commit comments

Comments
 (0)