【发布时间】:2019-12-14 23:46:48
【问题描述】:
我是 Spring WebFlux 的新手。我想读取存储在classpath resource 中的 JSON 文件并转换为 POJO 类。文件夹结构为resources/defaults/myjson.json。我正在使用杰克逊进行转换。阅读后,这将转换为MyJson.java。截至目前,我正在执行以下方法。
@Service
public class MyService {
private final ObjectMapper objectMapper;
private MyJson myJson;
@Autowired
public MyService(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
this.myJson = MyFileUtils.readFile(objectMapper, "classpath:/defaults/myjson.json", MyJson.class);
}
public MyJson getMyJson() {
return this.myJson;
}
}
还有其他方法吗?
【问题讨论】:
标签: spring-boot spring-webflux