In the latest release v1.2.0, code for AvroJsonOutputStream hard-coded the pretty option to true, as showing below:
@OptIn(ExperimentalSerializationApi::class)
class AvroJsonOutputStream<T>(output: OutputStream,
converter: (T) -> GenericRecord,
schema: Schema) : DefaultAvroOutputStream<T>(output, converter, schema) {
... ...
override val encoder: JsonEncoder =
EncoderFactory.get().jsonEncoder(schema, output, true) // here, set pretty option to true
}
It makes the JSON output not suitable for some data processing scenarios that requires no newLine in a json string. However, since the pretty option is hard-coded to true, there's no way for user to change it.
Reasons for not using workable like string replace ops or other JSON libraries:
using simple operations like replace("\n", "").replace(" ", "") is not safe to protect content in json fields.
using other JSON libraries (e.g. google GSON), AVRO JSON serialization/deserialization strategy is not aligned with them (e.g. how to treat nullable field, avro will output field with null, gson will swallow the null field).
So, I suggest to open the pretty option and configurable, and make AvroEncodeFormat's Json object becomes PrettyJson object and CompactJson object, as showing below
In the latest release v1.2.0, code for AvroJsonOutputStream hard-coded the
pretty
option totrue
, as showing below:It makes the JSON output not suitable for some data processing scenarios that requires no
newLine
in a json string. However, since the pretty option is hard-coded to true, there's no way for user to change it.Reasons for not using workable like string replace ops or other JSON libraries:
replace("\n", "").replace(" ", "")
is not safe to protect content in json fields.So, I suggest to open the pretty option and configurable, and make AvroEncodeFormat's
Json object
becomesPrettyJson object
andCompactJson object
, as showing belowFor AvroEncodeFormat
For AvroJsonOutputStream