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

Support @JsonFormat(shape=STRING) for serialization of Range<T> #118

Closed
chris-dekker opened this issue Jun 2, 2023 · 6 comments
Closed
Assignees
Labels
Milestone

Comments

@chris-dekker
Copy link

I find the standard serialization JSON, while flexible, of Range<T> to be quite verbose:

{
  "lower_endpoint": 12,
  "lower_bound_type": "CLOSED",
  "upper_endpoint": 34,
  "upper_bound_type": "OPEN"
}

When manually processing the results, I prefer to shorter notation produced by, among others, the default toString() invocation: [12..34).

Similar to Instant, where we can use @JsonFormat(shape = ..) to control (de)serialization to use the ISO format or unix milis, it would be great if we could control the shape of the range this way. Keep the default as-is and only when @JsonFormat(shape = STRING) is provided, use the shorter notation.

Granted, this will only work for endpoints having scalar values, but that seems to cover the majority of use cases I've seen so far.

@cowtowncoder cowtowncoder added guava good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project labels Jun 2, 2023
@cowtowncoder
Copy link
Member

Sounds like a good idea for someone with time & interest to work on, and solid improvement to usability. Tagged as such.

@saydar31
Copy link

saydar31 commented Jun 7, 2023

Assign it to me please,
Also I have a question: how should range without lower or upper bound look like?
(,1] or (-INF, 1], in my humble opinion second one looks better

@cowtowncoder
Copy link
Member

@saydar31 I let you decide. But does Guava's Range.toString() offer guidance here?

@chris-dekker
Copy link
Author

chris-dekker commented Jun 15, 2023

@saydar31 great to hear you're picking this up! Would prefer to stay consistent with the Range.toString() method indeed, which uses the symbol (\u221e)

@JooHyukKim
Copy link
Member

@saydar31 great to hear you're picking this up! Would prefer to stay consistent with the Range.toString() method indeed, which uses the symbol (\u221e)

@chris-dekker now that you mention it, this needs to go on the doc. I will add notes to the PR that whatever symbol Jackson returns, the returned unicode of symbol would also be documented.

mukham12 added a commit to mukham12/jackson-datatypes-collections that referenced this issue Dec 12, 2023
@cowtowncoder cowtowncoder removed the good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project label Dec 12, 2023
@cowtowncoder cowtowncoder added this to the 2.17.0 milestone Dec 12, 2023
@cowtowncoder cowtowncoder changed the title Support @JsonFormat(shape=STRING) on Range<T> Support @JsonFormat(shape=STRING) for serialization of Range<T> Dec 12, 2023
@cowtowncoder
Copy link
Member

Merged for inclusion in 2.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants