kaml icon indicating copy to clipboard operation
kaml copied to clipboard

Yaml and YamlConfiguration Builders

Open YuryMikhailuts opened this issue 2 years ago • 2 comments

Describe the problem you'd like to solve

When using other serialization libraries, I got used to the ability to create everything using builders. This is very lacking in this library.

Describe the solution you'd like

According to my ideas, it might look something like this:

fun Yaml(
	serializersModule: SerializersModule = EmptySerializersModule,
	configuration: YamlConfigurationBuilder.() -> Unit,
): Yaml = Yaml(
	serializersModule = serializersModule,
	configuration = YamlConfigurationBuilder().apply(configuration).build(),
)


class YamlConfigurationBuilder {
	var encodeDefaults: Boolean = true
	var strictMode: Boolean = true
	var extensionDefinitionPrefix: String? = null
	var polymorphismStyle: PolymorphismStyle = PolymorphismStyle.Tag
	var polymorphismPropertyName: String = "type"
	var encodingIndentationSize: Int = 2
	var breakScalarsAt: Int = 80
	var sequenceStyle: SequenceStyle = SequenceStyle.Block
	var singleLineStringStyle: SingleLineStringStyle = SingleLineStringStyle.DoubleQuoted
	var multiLineStringStyle: MultiLineStringStyle = singleLineStringStyle.multiLineStringStyle

	fun build() = YamlConfiguration(
		encodeDefaults = encodeDefaults,
		strictMode = strictMode,
		extensionDefinitionPrefix = extensionDefinitionPrefix,
		polymorphismStyle = polymorphismStyle,
		polymorphismPropertyName = polymorphismPropertyName,
		encodingIndentationSize = encodingIndentationSize,
		breakScalarsAt = breakScalarsAt,
		sequenceStyle = sequenceStyle,
		singleLineStringStyle = singleLineStringStyle,
		multiLineStringStyle = multiLineStringStyle,
	)
}

Describe alternatives you've considered

No response

Additional context

No response

YuryMikhailuts avatar Jun 19 '22 20:06 YuryMikhailuts

Hi @YuryMikhailuts, this looks good to me. Would you be interested in submitting a PR with this?

charleskorn avatar Jun 20 '22 03:06 charleskorn

Hi @YuryMikhailuts, this looks good to me. Would you be interested in submitting a PR with this?

Unfortunately, I have a lot of work to do right now. Creating this discussion is all I can do right now. It is possible that I will join your project later.

YuryMikhailuts avatar Jun 20 '22 05:06 YuryMikhailuts

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. If this issue is still affecting you, please comment below within the next seven days. Thank you for your contributions.

stale[bot] avatar Aug 30 '22 17:08 stale[bot]

This issue has been automatically closed because it has not had any recent activity.

stale[bot] avatar Sep 06 '22 17:09 stale[bot]