您好我正在尝试将 vavr 添加到我的项目中,现在我正在努力正确序列化 Vavr.List 对象。下面是我的控制器:
import io.vavr.collection.List;
@GetMapping(value = "/xxx")
public List<EntityDeleted> getFile() {
return List.of(new EntityDeleted(true),new EntityDeleted(true),new EntityDeleted(true),new EntityDeleted(true));
}
EntityDeleted 是我的自定义对象,List 是 Vavr 集合,如导入语句中所示。我在邮递员中得到的回应是:
{
"empty": false,
"lazy": false,
"async": false,
"traversableAgain": true,
"sequential": true,
"singleValued": false,
"distinct": false,
"ordered": false,
"orNull": {
"deleted": true
},
"memoized": false
}
我期望我的对象的 JSON 列表。下面是我的配置:
@SpringBootApplication
public class PlomberApplication {
public static void main(String[] args) {
SpringApplication.run(PlomberApplication.class, args);
}
@Bean
public ObjectMapper jacksonBuilder() {
ObjectMapper mapper = new ObjectMapper();
return mapper.registerModule(new VavrModule());
}
}
和一点 pom.xml
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr-jackson</artifactId>
<version>0.9.0</version>
</dependency>