0

Giving the following code:

ArrayList<ActionOutput> res = manager.getRes();
ObjectWriter objectWriter = objectMapper.writer();
objectWriter = objectWriter.withDefaultPrettyPrinter();
objectWriter.writeValue(new File(args[1]), res);

Let's say a member from ActionOutput is a list of objects, and that object contains a double instance variable.

I want to print in a file that double with precision at .00 (13.2 -> 13.20, 14.23423 -> 14.23).

How can I configure my objectWriter to write my JSON file this way?

  • A custom serializer is probably needed for that. Depending on whether you require the precision to be hard-coded or not, here are some SO answers to guide you: [hard-coded](https://stackoverflow.com/a/53284909/639520) and [annotation-driven](https://stackoverflow.com/a/44128440/639520). – E-Riz Dec 09 '22 at 16:54

0 Answers0