Description
Hi, I'm trying to update some attributes with a custom query, but I get the following exception :
exception
com.couchbase.client.core.error.InvalidArgumentException: Unsupported type for JSON value: class com.rbleuse.spring.reactive.couchbase.model.Person
at com.couchbase.client.core.error.InvalidArgumentException.fromMessage(InvalidArgumentException.java:28) ~[core-io-2.3.4.jar:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP PUT "/classroom" [ExceptionHandlingWebHandler]
Original Stack Trace:
at com.couchbase.client.core.error.InvalidArgumentException.fromMessage(InvalidArgumentException.java:28) ~[core-io-2.3.4.jar:na]
at com.couchbase.client.java.json.JsonValue.coerce(JsonValue.java:94) ~[java-client-3.3.4.jar:na]
at com.couchbase.client.java.json.JsonArray.add(JsonArray.java:178) ~[java-client-3.3.4.jar:na]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.putPositionalValue(StringBasedN1qlQueryParser.java:495) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.getPositionalPlaceholderValues(StringBasedN1qlQueryParser.java:437) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.getPlaceholderValues(StringBasedN1qlQueryParser.java:486) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.core.query.StringQuery.toN1qlSelectString(StringQuery.java:80) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
Here is my document :
@Document
@Scope("dev")
@Collection("classroom")
data class Classroom(
@field:Id
val id: String,
@field:Field
val person: Person,
@field:Field
val roomNumber: String
)
Here is my Person :
data class Person(
@field:Field
val firstName: String,
@field:Field
val lastName: String
)
And here is my query :
@Query("""
UPDATE #{#n1ql.bucket} c
USE KEYS $1 SET
c.person = $2
WHERE c.#{#n1ql.filter}""")
fun updateClassroom(id: String, person: Person)
It seems that the sdk requires a json object, so the only workaround I can think of is converting my Person with the MappingCouchbaseConverter.write(source, target)
which will convert with correct field names and types.
But this is an ugly solution, as the converter requires an id
attribute else it'll throw An ID property is needed, but not found
- Is that possible to update some of my document attributes without manually convert my parameters ?
- Is there any other elegant solution ?