Description
When I have the following classes:
enum Status { A,B }
@Document
class Entity { @Field Status status; }
I can write and read entities from the DB with no issues. However, when I create a function that would search for entities using status, it fails with
com.couchbase.client.core.error.InvalidArgumentException: Unsupported type for JSON value: class Status
at com.couchbase.client.java.json.JsonValue.coerce(JsonValue.java:94)
at com.couchbase.client.java.json.JsonArray.add(JsonArray.java:178)
at org.springframework.data.couchbase.core.query.QueryCriteria.maybeWrapValue(QueryCriteria.java:387)
Looking into the code, I see that QueryCriteria
tries to convert Enum using AbstractCouchbaseConverter.convertForWriteIfNeeded
. There it first looks converter up in CouchbaseCustomConversions
but can't find it as conversions know about their own and parent converters only.
converters.addAll(DateConverters.getConvertersToRegister());
converters.addAll(CouchbaseJsr310Converters.getConvertersToRegister());
defaults.addAll(JodaTimeConverters.getConvertersToRegister());
defaults.addAll(Jsr310Converters.getConvertersToRegister());
defaults.addAll(ThreeTenBackPortConverters.getConvertersToRegister());
However, the actual conversion would be performed, if conversion found, by conversionService
which is DefaultConversionService
and this guy actually knows how to convert to and from Enum.
Adding custom implementations into CouchbaseCustomConversions
solves this but I feel like it should not be necessary considering DefaultConversionService
can do this already.