从另一个模块读取或加载 JSON 文件

Reading or loading JSON file from another module

我想从另一个模块的 /resources 目录 read/load 一个 JSON 文件到当前模块,并使用 jackson 映射 JSON

当前模块名称是"transform",我需要的资源文件在另一个名为"schema"的模块中。我在 "transform" 模块的 pom.xml 文件中添加了 "schema" 作为 maven dependency

我需要在 "schema" 模块中 read/load 一个名为 "example.json" 的文件。

但我不断收到以下错误:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input.

我目前拥有的:

Map<String, String> map = objectMapper.readValue(
                getClass().getClassLoader().getResourceAsStream("/schema/resources/example.json"),
                                                new TypeReference<Map<String, String>>(){});

假设 example.json 的完整路径是“/schema/resources/example.json”.

Map<String, String> map = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream("/schema/resources/example.json"),
                                            new TypeReference<Map<String, String>>(){});