Unsupported type for JsonArray: class java.util.LinkedHashMap

Updating a subobject with Spring Data for Couchbase

I do this query in the Couchbase console and it is working fine

UPDATE `dev_h` USE KEYS "12" SET _data.payload = { "name": "new_name", "language": "new_language"}

I want to translate the query in the Spring Data repository

@Query("UPDATE #{#n1ql.bucket} USE KEYS "$1" SET _data.payload = $2	")
void update(String id, Map<String, String> newPayload);

but I have this Error

java.lang.IllegalArgumentException: Unsupported type for JsonArray: class java.util.LinkedHashMap

Hi Sandro,

I commented over on StackOverflow but I’ll add a little more detail here. I think internally Spring Data Couchbase is using a JsonArray object to represent the parameter list. A JsonArray can only contain a limited set of types, and Map is not one of them.

As a workaround, instead of a Map you should be able to use com.couchbase.client.java.document.json.JsonObject. Ideally this conversion would happen automatically, but we’re not there yet (tracking the issue as JCBC-1574)

So your method definition would look like this:

void update(String id, JsonObject newPayload);

I’m not sure, but I have a hunch that will work.

Thanks,
David

1 Like