0

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 にコーデックを登録するにはどうすればよいですか?

4

1 に答える 1