Skip to content

Allow use of @JsonFormat(shape=Shape.STRING) for string[], int[], long[] #1242

Open

Description

@cowtowncoder

There is some usage (esp. via Java properties files) where "simple" arrays are expressed as comma-separated lists, like so:

{
   "hosts" : "localhost:8080, otherhost.com:8080"
}

and it would seem reasonable to allow use of Shape.STRING for this.

A related question is that of how to indicate pattern to use; simplest starting point is probably to allow use of pattern to refer to separator to use; and consider "" to either detault to something like [\s*,\s*], or lead to exception for missing pattern.

Activity

  1. added
    3.x
    on Apr 9, 2025
  2. JacksonJang commented on Jan 12, 2026

    @JacksonJang
    Contributor

    Is this plan still valid?

    My thought is that when the default pattern value is "", we could treat it as \s*,\s* by default,
    and only fail when an explicit option such as FAIL_ON_* is enabled.

    This is because using [\s*,\s*] results in values like
    [localhost:8080, , otherhost.com:8080],
    whereas using \s*,\s* produces
    [localhost:8080, otherhost.com:8080].

    What do you think about this approach?

  3. cowtowncoder commented on Jan 12, 2026

    @cowtowncoder
    MemberAuthor

    This is more a general idea than plan, FWTW.

    And there is the big question of how (or, if) to support reading and writing: for most @JsonFormat cases either only writing (serialization) is supported, or both. Here I wrote issue implying maybe only reading was supported... but I think both should be supported. That does get trickier however; and @JsonFormat has no mechanism to indicate separate patterns for reading/writing.

    So, I am not sure how practical this idea really is.

    More generally the idea is just that it'd be nice to have "primitive/String arrays to/from JSON String", my suggested pattern (of separator definition) was just very basic thinking-out-loud example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions