Skip to content

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

@chris-dekker

Description

@chris-dekker

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions