Spring Data Couchbase:方法findBy对象抛出java.lang.IllegalArgumentException“ JsonArray不支持的类型”

问题描述 投票:0回答:1

我创建了一个Spring Boot项目。指定的数据模型:


@Document
public class User {

    @Id
    private String id;

    @Field
    private String firstname;

    @Field
    private List<Child> children;

    public User(String id, String firstname, List<Child> children) {
        this.id = id;
        this.firstname = firstname;
        this.children = children;
    }

    static class Child {
        private String name;
        private int age;

        Child(String name, int age) {
            this.name = name;
            this.age = age;
        }

    }

}

还创建了反应性存储库:

@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "UserView")
public interface UserViewRepository extends ReactiveCouchbaseSortingRepository< UserView, String> {
 List<User> findByChild(Child child);
 List<User> findByFirstname(String firstname);
}

调用方法findByChild已生成异常:

java.lang.IllegalArgumentException: Unsupported type for JsonArray: class ru.andyhunt.user.User.Child
    at com.couchbase.client.java.document.json.JsonArray.add(JsonArray.java:214) ~[java-client-2.7.11.jar:na]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ HTTP GET "/users" [ExceptionHandlingWebHandler]
Stack trace:
        at com.couchbase.client.java.document.json.JsonArray.add(JsonArray.java:214) ~[java-client-2.7.11.jar:na]
        at org.springframework.data.couchbase.repository.query.support.N1qlQueryCreatorUtils.createExpression(N1qlQueryCreatorUtils.java:94) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.couchbase.repository.query.support.N1qlQueryCreatorUtils.prepareExpression(N1qlQueryCreatorUtils.java:66) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.couchbase.repository.query.N1qlQueryCreator.create(N1qlQueryCreator.java:109) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.couchbase.repository.query.N1qlQueryCreator.create(N1qlQueryCreator.java:88) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
        at org.springframework.data.couchbase.repository.query.ReactivePartTreeN1qlBasedQuery.getStatement(ReactivePartTreeN1qlBasedQuery.java:72) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.couchbase.repository.query.ReactiveAbstractN1qlBasedQuery.execute(ReactiveAbstractN1qlBasedQuery.java:62) ~[spring-data-couchbase-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:618) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]

版本:Spring boot 2.2.2.RELEASEspring-data-couchbase-3.2.3.RELEASE

为什么Spring-Data扩展不能将User对象转换为JsonObject?但是,方法getByFirstname可以正常工作。

谢谢!

spring spring-data couchbase illegalargumentexception spring-data-couchbase
1个回答
0
投票

有多个JsonArray类,请查看您要导入的类,以确保它是根据需要的jsonarray

© www.soinside.com 2019 - 2024. All rights reserved.