mongodb - Quarkus PanacheMongoEntity - Enum 没有自动编码/解码吗?
问题描述
这是我的实体“WebhookType”:
public class WebhookType extends PanacheMongoEntity {
public ObjectId id;
public String type;
public String name;
public String description;
public String image;
public List<WebhookTypeParameter> webhookTypeParameters = new ArrayList<>();
}
其中有一个“WebhookTypeParameters”列表:
public class WebhookTypeParameter {
public Enum<ParameterType> parameterType;
public String parameterName;
public String parameterExample;
public WebhookTypeParameter(){
}
public Enum<ParameterType> getParameterType() {
return parameterType;
}
public void setParameterType(Enum<ParameterType> parameterType) {
this.parameterType = parameterType;
}
public String getParameterName() {
return parameterName;
}
public void setParameterName(String parameterName) {
this.parameterName = parameterName;
}
public String getParameterExample() {
return parameterExample;
}
public void setParameterExample(String parameterExample) {
this.parameterExample = parameterExample;
}
public WebhookTypeParameter(String parameterName, Enum<ParameterType>parameterType, String parameterExample){
this.setParameterName(parameterName);
this.setParameterType(parameterType);
this.setParameterExample(parameterExample);
}
}
其中有一个 Enum 类型的字段“parameterType”:
public enum ParameterType {
STRING, DOUBLE;
}
现在,当尝试像这样坚持我的实体时:
WebhookType webhookType = new WebhookType();
webhookType.type = "XYZ";
webhookType.name = "XYZ";
webhookType.image = "image url";
webhookType.description = ("Lorem Ipsum");
webhookType.webhookTypeParameters.add(new WebhookTypeParameter("title", ParameterType.STRING, "titel xy"));
webhookType.webhookTypeParameters.add(new WebhookTypeParameter("name", ParameterType.STRING, "foobar"));
webhookType.persist();
我在我的日志中得到这个:
2020-09-19 14:01:07,587 ERROR [io.qua.application] (Quarkus Main Thread) Failed to start application: org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when encoding using the AutomaticPojoCodec.
Encoding a WebhookType: 'WebhookType<null>' failed with the following exception:
Failed to encode 'WebhookType'. Encoding 'webhookTypeParameters' errored with: An exception occurred when encoding using the AutomaticPojoCodec.
Encoding a WebhookTypeParameter: 'x.x.x.WebhookTypeParameter@474d3e58' failed with the following exception:
Failed to encode 'WebhookTypeParameter'. Encoding 'parameterType' errored with: Can't find a codec for class x.x.x.ParameterType.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
所以我的问题是我的枚举有什么问题,为什么它没有自动编码?
解决方案
推荐阅读
- python - (Python3)多次访问字典更好,还是对项目的值进行引用?
- firebase - Flutter Firebase RealTime Databasee 无法使用 OrderByChild() 正确排序
- python - 使用 ProtoBuf 的相对导入:使用 ProtoBuf 生成 Python 类会给出 ModuleNotFoundError
- r - 基于 $ 提取单词并取消嵌套数据
- php - 如何将 Javascript 小程序嵌入 Wordpress 中的元框
- javascript - 是否可以将 svg g 转换为 html div?
- unity3d - 在代码中更改车轮碰撞器中的参数
- image - 验证集扩充 PyTorch 示例
- javascript - 收集输入数据并在 div 中显示
- python - 从 .txt 文件中删除