我正在尝试使用 quarkus-mongodb-panache 将 JSONArray 存储和检索到 mongo db。
import io.quarkus.mongodb.panache.MongoEntity;
import io.quarkus.mongodb.panache.PanacheMongoEntity;
import org.json.simple.JSONArray;
@MongoEntity(collection="data")
public class A extends PanacheMongoEntity {
public LocalDate insertTime;
public JSONArray data;
public static void save(A a) {
persist(a);
}
public static A findByDate(LocalDate localDate) {
return find("insertTime", localDate).firstResult();
}
}
我能够将 JSONArray 存储到 mongodb 并且无法检索它。我在阅读 mongodb 条目时遇到下面提到的错误。
Resulted in: org.bson.codecs.configuration.CodecConfigurationException: Unable to set value for property 'data' in A
at org.bson.codecs.pojo.PropertyAccessorImpl.setError(PropertyAccessorImpl.java:74)
at org.bson.codecs.pojo.PropertyAccessorImpl.set(PropertyAccessorImpl.java:60)
... 97 more
Resulted in: org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'A'. Decoding 'data' errored with: Unable to set value for property 'data' in A
at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:225)
... 95 more
Resulted in: org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'A' failed with the following exception:
Failed to decode 'A'. Decoding 'data' errored with: Unable to set value for property 'data' in A
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40)
... 91 more
Resulted in: org.jboss.resteasy.spi.UnhandledException: org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
我认为如果我提供 mongo-jackson-codec 可以解决这个问题。但是如何在 mongodb-panache 中注册编解码器?