Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to serialize List<String> as "comma,separated,value" #1

Open
cowtowncoder opened this issue Mar 19, 2017 · 4 comments
Open
Labels
Properties Issue related to (Java) Properties format backend

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 19, 2017

(note: moved from https://github.com/FasterXML/jackson-dataformat-properties/issues/5)

Comma-separated lists are quite common in property or *.ini style configuration files. The only way I found to generate/parse these with JavaPropsMapper is to annotate a custom value class with @JsonCreator and @JsonValue, but this also affects other data formats that do have a proper list representation. If I want to convert between *.ini and json/yaml/xml, it gets quite messy.

I would like to propose (and help with) the following feature: Arrays or lists of primitive types can be configured to be serialized and deserialized as CSV (Split at configurable delimiter, strip whitespace around delimiter, do not split or remove whitespace within quoted strings, remove quotes from quoted strings).

This would make *.ini style configuration a real alternative to json/yaml/xml for some use cases.

@cowtowncoder
Copy link
Member Author

Yes, agreed. Timely RFE as well, due to:

FasterXML/jackson-databind#1364

which is for the same thing, but applying generally, via @JsonFormat. There are some open questions on possibly configuration, how to make serialization also work, and a thread on jackson-dev trying to figure out what would be the best way to go.

I don't think a ton of configuration would be needed, but seems like separator char (comma, semicolon, space, sometimes pipe) may vary, and perhaps what whitespace to allow/add before/after separator.

Questing of possible quoting of values within is an interesting one and I hadn't considered that. I know that CSV does that, but haven't seen widely used with other formats.

@cowtowncoder cowtowncoder added the Properties Issue related to (Java) Properties format backend label Mar 20, 2017
@TWiStErRob
Copy link

This would be useful for XML too.

My current workaround is:

data class SplitStringValues(
	/**
	 * @sample `"a,bb,ccc"`
	 */
	val vals: String
) {

	constructor(vals: List<String>) : this(vals.joinToString(","))

	@JsonIgnore
	val valList = vals.split(",")
}
<SplitStringValues>
	<vals>a,bb,ccc</vals>
</SplitStringValues>

but this gets hairy if vals is an attribute among other properties on a bigger object.

@Pytry
Copy link

Pytry commented Oct 11, 2021

Just wondering is anything has been done on this or not?

@cowtowncoder
Copy link
Member Author

cowtowncoder commented Oct 12, 2021

If something is done, something is noted on the issue typically. I am not aware of any related work.

PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Properties Issue related to (Java) Properties format backend
Projects
None yet
Development

No branches or pull requests

3 participants