From 08bf6981f5768897707851dc011d3898e4bd5c1a Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Fri, 7 Aug 2026 17:00:10 -0400 Subject: [PATCH] Allow changing only JSON output whitespace options Add a secondary constructor to `JSONOutputArchive::Options` that allows users to change the whitespace options while retaining the default floating point precision. --- include/cereal/archives/json.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/cereal/archives/json.hpp b/include/cereal/archives/json.hpp index f86bcd40e..c4d63bc1f 100644 --- a/include/cereal/archives/json.hpp +++ b/include/cereal/archives/json.hpp @@ -123,7 +123,7 @@ namespace cereal static Options Default(){ return Options(); } //! Default options with no indentation - static Options NoIndent(){ return Options( JSONWriter::kDefaultMaxDecimalPlaces, IndentChar::space, 0 ); } + static Options NoIndent(){ return Options( IndentChar::space, 0 ); } //! The character to use for indenting enum class IndentChar : char @@ -139,13 +139,23 @@ namespace cereal @param indentChar The type of character to indent with @param indentLength The number of indentChar to use for indentation (0 corresponds to no indentation) */ - explicit Options( int precision = JSONWriter::kDefaultMaxDecimalPlaces, + explicit Options( int precision, IndentChar indentChar = IndentChar::space, unsigned int indentLength = 4 ) : itsPrecision( precision ), itsIndentChar( static_cast(indentChar) ), itsIndentLength( indentLength ) { } + //! Specify specific options for the JSONOutputArchive + /*! @param indentChar The type of character to indent with + @param indentLength The number of indentChar to use for indentation + (0 corresponds to no indentation) */ + explicit Options( IndentChar indentChar = IndentChar::space, + unsigned int indentLength = 4 ) : + itsPrecision( JSONWriter::kDefaultMaxDecimalPlaces ), + itsIndentChar( static_cast(indentChar) ), + itsIndentLength( indentLength ) { } + private: friend class JSONOutputArchive; int itsPrecision;