Reputation: 481
I'm writing a command line app that needs to serialize/deserialize a json file but can't seem to find a non-web example. All the code I found is to do with Restful API and Web.
So the question is how to set up serializer/deserializer and map pojos to json in a Spring boot command line app. It'd be great if there is a sample unit test that shows how to set up its Spring content. I tried the code snippet in Spring boot docs using @JsonTest Auto-configured JSON tests but it complains of not finding matching implementation.
Many thanks
Upvotes: 0
Views: 348
Reputation: 489
Take a look at the Jackson project, specifically the ObjectMapper.
https://github.com/FasterXML/jackson
The simplest way would be to create an ObjectMapper as a bean, and use that throughout your project.
@Configuration
public class MyConfig() {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper() ;
}
}
Upvotes: 1