-
Notifications
You must be signed in to change notification settings - Fork 192
Support BigDecimal fields in documents with jdk17 #1439
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
Comments
I tried to reproduce this by adding a BigInteger field to User and running the integration tests. There were no failures. Could you provide the entity class? Or your github project? BigInteger is supposed to be handled by BigIntegerToString and StringtoBigInteger Converters
|
I added the tests below and they pass. They use the converters from OtherConverters. Is it possible that you are using a CustomCouchbaseConverter that does not include OtherConverters (it will come from new CouchbaseCustomConversions(Collections.emptyList())) ? Or a couchbaseMappingContext that does not make use of customConversions? couchbaseCustomConversions bean which is an arg to
Tests I added to MappingCouchbaseConverterTests that pass:
|
Hi @mikereiche First of all, thank you for the quick response. My problem es with BigDecimal (with BigInteger works). I attach a demo as simple as possible and when I start the app I get the error I mentioned before. |
I have bad reading skills. I will add a converter for BigDecimal to OtherConverters and that will fix your problem. When I do that, you should be able to pick it up from 5.0.0-SNAPSHOT. |
Same issue with Java 17 and Spring Boot 2.7.0 (spring-data-couchbase 4.4.0) |
Hi, we have managed to solve this issue for versions Java:17, Spring:2.6.2, Spring-Data-Couchbase:4.3.0 by adding this line below to getMappingCouchbaseConverter() method as mentioned in the example below. ((CouchbaseMappingContext) mappingCouchbaseConverter.getMappingContext()).setSimpleTypeHolder(customConversions.getSimpleTypeHolder()); This line adds our converter to Couchbase context from start. Without adding this line, the program was giving this error:
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
private final ApplicationContext applicationContext;
@Bean
public CouchbaseTemplate bucketTemplate() {
return new CouchbaseTemplate(bucketFactory(), getMappingCouchbaseConverter());
}
public CouchbaseClientFactory bucketFactory() {
return new SimpleCouchbaseClientFactory(getCluster(), “bucketName”, null);
}
@Bean
public Cluster getCluster() {
return Cluster.connect(“connectionString”, “username”, “password”);
}
public MappingCouchbaseConverter getMappingCouchbaseConverter() {
MappingCouchbaseConverter mappingCouchbaseConverter = new MappingCouchbaseConverter();
CustomConversions customConversions = customConversions();
mappingCouchbaseConverter.setCustomConversions(customConversions);
mappingCouchbaseConverter.setApplicationContext(applicationContext);
mappingCouchbaseConverter.afterPropertiesSet();
((CouchbaseMappingContext) mappingCouchbaseConverter.getMappingContext()).setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
return mappingCouchbaseConverter;
}
public CustomConversions customConversions() {
return new CouchbaseCustomConversions(
Arrays.asList(
CouchbaseFieldsConverters.BigDecimalToStringConverter.INSTANCE,
CouchbaseFieldsConverters.StringToBigDecimalConverter.INSTANCE
)
);
}
}
public class CouchbaseFieldsConverters {
@WritingConverter
public enum BigDecimalToStringConverter implements Converter<BigDecimal, String> {
INSTANCE;
@Override
public String convert(BigDecimal source) {
return source == null ? null : source.toString();
}
}
@ReadingConverter
public enum StringToBigDecimalConverter implements Converter<String, BigDecimal> {
INSTANCE;
@Override
public BigDecimal convert(String source) {
return source == null ? null : new BigDecimal(source);
}
}
} But, as mentioned above, after adding the BigDecimal converter to OtherConverters by default in 5.0.0-SNAPSHOT, we won't need to add this line anymore. |
This workaround works for me. Thank you |
Add BigDecimal converter, add converter tests for BigDecimal and BigInteger. Since BigDecimail is not support, it cannot be used in the CustomerConverter tests. So instead use ChoiceFormat for CustomConverter tests. Closes #1439.
Add BigDecimal converter, add converter tests for BigDecimal and BigInteger. Since BigDecimail is not support, it cannot be used in the CustomerConverter tests. So instead use ChoiceFormat for CustomConverter tests. Closes #1439.
Hi
I am testing jdk17 in an application that contains a field in a document of type
BigDecimal
.On application startup, I get the following error:
Trace
Versions
Related issue: #1278
Workaround:
Add JVM Parameter
--add-opens java.base/java.math=ALL-UNNAMED
The text was updated successfully, but these errors were encountered: