On Thu, Sep 15, 2016 at 1:15 AM, lokesh N <nlokesh...@gmail.com> wrote:

> This discussion is about representing comma separated lists for String[],
> int[] and long[]. An example representing String[] as comma separated list
> would be,
>
> {
>   "StringArr": "item1,item2,item3"
> }
>
> To represent this comma separated format, we will use @JsonFormat
> annotation with a pattern of something like "\w+(,\w)*". The pattern
> represented here is a regex pattern which can be applied on a string to get
> the list of values while deserialization, but while serialization we cannot
> use this regex pattern to serialize an array into a string separated by a
> delimiter.
>
> One suggestion would be to use a static pattern for representing the comma
> separated values like "\w,\w" which we can use to serialize and deserialize
> the comma separated scalars and strings.
>
> Let me know your thoughts.
>
>
First of all, I think this is a great idea, since this pseudo-format is
commonly used. And especially so for other textual formats like XML, CSV
and properties files. There is some specialized handling for CSV, but
nothing shared.

One open question that I have is regarding parity with serialization: it
would be great if this would work not only when deserializing (reading),
but also when writing. But doing that would impose limitations on
specifying how formatter is defined; and generalized regular expressions
(for example) would not work. On the other hand, use of printf-style format
strings could work.

I guess it could be possible to add another property, `outputFormat`, which
could take different expressions, as one possibility.

But if a single regexp was used to represent separator, it might actually
be possible to re-write regexp using some heuristics, to produce a constant
string. For example, something like ",\w+" would become ", " (single space)
and ",\w*" "," (no trailing space); replacing \w with space, possible
character classes with the first character of the group; "+" meaning "one",
"*" meaning "zero".
Point being that deserialization would use full expression, and
serialization a simplified canonical version.

What do others think?

-+ Tatu +-




> Thanks,
> Lokesh
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jackson-dev+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to