带有 UUID 字段的问题序列化 Panache 实体

时间:2021-07-05 16:32:25

标签: mongodb serialization

如果有这个

@Data
@MongoEntity(collection = "shipments")
@EqualsAndHashCode(callSuper = false)
public class Shipment extends PanacheMongoEntity {

    public enum ShipmentStatus {
        UNDEFINED,
        OK;
    }

    public ObjectId id;
    public String trackingNumber;

    public UUID rateId

当我尝试这样做时:

shipment.persist()

我明白了:

An exception occurred when encoding using the AutomaticPojoCodec.

Failed to encode 'Shipment'. **Encoding 'rateId' errored with: The uuidRepresentation has not 
been specified, so the UUID cannot be encoded.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this 
type.

问题似乎是 Panache 无法使用 PojoCodecProvider 序列化属性 UUID rateId 字段。

我是否需要为完整实体提供代码,例如:

public class ShipmentCodec implements CollectibleCodec<Shipment>

或者我可以注册类似的东西

public class UUIDCodec implements Codec<UUID>

请帮忙!!

谢谢!

罗伯特

0 个答案:

没有答案
相关问题