java - 是否可以解析地图> 在用于 Java Dropwizard 的 Yaml 中
问题描述
我有一个问题,我试图使用 a 解析 yaml 文件,Map<String, Pin>
但 Dropwizard 一直抱怨它无法解析它。
我的 Yaml 文件如下所示 -
us:
baseUrl: https://www.example.com
fixture1: https://www.example.com/fixture1
fixture2: https://www.example.com/fixture2
filters:
pins:
fixture1:
- category: test_category1
urls:
- url: https://www.example.com/fixture1/test
name: fixture1 entry
weight: 1000
fixture2:
- category: test_category_2
urls:
- url: https://www.example.com/fixture2/test
name: fixture2 entry
weight: 1000
我使用杰克逊用代码解析它
try {
Map<String, Country> countries = mapper.readValue(getClass().getResourceAsStream(COUNTRY_CONFIG_FILE),
new TypeReference<Map<String, Country>>() {
});
} catch (IOException e) {
throw new CrossLinkerException("Country config is null");
}
Country 对象是一个 pojo,具有以下属性
public class Country {
private String baseUrl;
private String goodsUrl;
private String localUrl;
private TestFilter filters;
}
class TestFilter {
private Map<String, List<Pin>> pins;
}
public class Pin {
private String category;
private List<Link> urls;
}
public class Link {
private String url;
private String name;
private Float weight;
}
当我启动应用程序时,它失败并出现错误 Country config is null。
解决方案
推荐阅读
- nginx - Nginx - 是否可以知道选择了哪个服务器?
- java - Java:JSON 使用 GSON 进行映射
- java - Android ndk-build 命令失败
- view - 如何制作像 WheelView 这样的循环项目列表?
- c++ - 如何在 OpenGL 中进行 2D 缩放(GLFW,很高兴)?
- html - 相当于 SVG 中的背景位置百分比 (%)
- javascript - 使用 JavaScript 使用 WooCommerce REST API
- gradle - 为什么命令行与dependsOn中的任务解析不同?
- ios - 从 Firebase 存储 (Swift) 下载图像的问题
- javascript - 如何在javascript中对对象列表数组进行排序?