diff --git a/src/main/kotlin/com/autonomousapps/internal/utils/moshi.kt b/src/main/kotlin/com/autonomousapps/internal/utils/moshi.kt index 022f33cd8..2d84f9d8f 100644 --- a/src/main/kotlin/com/autonomousapps/internal/utils/moshi.kt +++ b/src/main/kotlin/com/autonomousapps/internal/utils/moshi.kt @@ -117,7 +117,7 @@ inline fun File.bufferWriteJsonMap( indent: String = noJsonIndent ) { JsonWriter.of(sink().buffer()).use { writer -> - getJsonMapAdapter(withNulls).indent(indent).toJson(writer, set) + getJsonMapAdapter(withNulls).indent(resolveIndent(indent)).toJson(writer, set) } } @@ -130,7 +130,7 @@ inline fun File.bufferWriteJsonMap( */ inline fun File.bufferWriteJsonMapSet(set: Map>, indent: String = noJsonIndent) { JsonWriter.of(sink().buffer()).use { writer -> - getJsonMapSetAdapter().indent(indent).toJson(writer, set) + getJsonMapSetAdapter().indent(resolveIndent(indent)).toJson(writer, set) } } @@ -153,7 +153,7 @@ inline fun File.bufferPrettyWriteJsonList(set: List) { */ inline fun File.bufferWriteJsonList(set: List, indent: String = noJsonIndent) { JsonWriter.of(sink().buffer()).use { writer -> - getJsonListAdapter().indent(indent).toJson(writer, set) + getJsonListAdapter().indent(resolveIndent(indent)).toJson(writer, set) } } @@ -176,7 +176,7 @@ inline fun File.bufferPrettyWriteJsonSet(set: Set) { */ inline fun File.bufferWriteJsonSet(set: Set, indent: String = noJsonIndent) { JsonWriter.of(sink().buffer()).use { writer -> - getJsonSetAdapter().indent(indent).toJson(writer, set) + getJsonSetAdapter().indent(resolveIndent(indent)).toJson(writer, set) } } @@ -189,7 +189,7 @@ inline fun File.bufferWriteJsonSet(set: Set, indent: String = noJ */ inline fun File.bufferWriteJson(set: T, indent: String = noJsonIndent) { JsonWriter.of(sink().buffer()).use { writer -> - getJsonAdapter().indent(indent).toJson(writer, set) + getJsonAdapter().indent(resolveIndent(indent)).toJson(writer, set) } } @@ -199,11 +199,15 @@ inline fun File.bufferWriteParameterizedJson( ) { JsonWriter.of(sink().buffer()).use { writer -> MOSHI.adapter(newParameterizedType(A::class.java, B::class.java)) - .indent(indent) + .indent(resolveIndent(indent)) .toJson(writer, parameterizedData) } } +fun resolveIndent(indent: String): String { + return if (System.getProperty("com.autonomousapps.pretty-json") == null) indent else prettyJsonIndent +} + @Suppress("unused") internal class TypeAdapters {