【发布时间】:2014-07-18 08:06:59
【问题描述】:
我有这个 .yml 文件:
template: Hello, testapp!
storage:
storageUri: ****************
storageAccessKey: ****************
storageSecretKey: *******************
buckets:
"one": one-buck-name
"second": second-buck-name
buckets:
- tag: one
name: one-buck-name
- tag: second
name: second-buck-name
one:
bucket: one-buck-name
second:
bucket: second-buck-name
在“storageSecretKey”下方,我有三种不同的方式来定义我的存储桶的配置。 所以我用java解析这个配置有很多问题。
对于第一个配置,我使用过:
@NotNull private ImmutableMap<String, String> buckets = ImmutableMap.of();
出现此错误:
testapp.yml has an error: * Unrecognized field at: storage.buckets
Did you mean?:
- storageUri
- storageAccessKey
- storageSecretKey
使用第二种配置(仅适用):
@有效 @NotNull 私有列表存储桶 = Lists.newArrayList(); 公共静态类桶{
@Valid
@NotNull
@JsonProperty
private String tag;
@Valid
@NotNull
@JsonProperty
private String name;
public Bucket(){}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
最后,对于第三个配置:
@Valid
@NotNull
@JsonProperty
private One one;
@Valid
@NotNull
@JsonProperty
private Second second;
public class One {
@Valid
@NotNull
@JsonProperty
private String bucket;
public String getBucket() {
return bucket;
}
}
public class Second {
@Valid
@NotNull
@JsonProperty
private String bucket;
public String getBucket() {
return bucket;
}
}
出现此错误:
testapp.yml has an error:
* Failed to parse configuration at: storage.one.bucket; Can not deserialize instance of java.lang.String out of END_OBJECT token
at [Source: N/A; line: -1, column: -1] (through reference chain: com.testapp.configurations.AppConfiguration["storage"]->com.testapp.configurations.StorageConfiguration["chat"]->com.testapp.configurations.One["one"])
注意:第三种配置与 dropwizard 0.6.2 完美配合。
最新信息:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.1</version>
</dependency>
解析这个该死的存储配置的正确方法在哪里?
【问题讨论】:
标签: java jackson yaml dropwizard