question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `@JsonFormat` for `String`, numbers, using String.format()

See original GitHub issue

Seems like it would be nice to just support formats available via format Strings that String.format() uses. Note that existing support for date/time values use different formatting; this should be fine, and if we want to for some reason support something from java.text.Format it should be possible to use heuristics to determine intended type of format. However that may not be necessary.

Initially we should just support simple types:

  • java.lang.String
  • int, long, short, byte, float, double and matching wrapper types
  • BigDecimal, BigInteger

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mincong-hcommented, Dec 25, 2019

Hi @cowtowncoder , does this issue mean supporting the use-case below, where @JsonFormat is used to contextualize the serialization?

   static class IntAsThousandSeparatedString {
       @JsonFormat(shape=Shape.STRING, pattern="%,d")
       @JsonProperty("value")
       public int foo = 3_000;
   }

And it should be serialized as follow:

{ "value" : "3,000" }

I understand that it should support other numeric types and different locales as well. I would like to contribute on this one. If you could give me some hints about where to get started, that will be great.

0reactions
Ikki-Daicommented, Aug 31, 2022

Hope this feature can be implement, spring framework has a @NumberFormat annotation provide similar feature!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to @JsonFormat in Jackson - Baeldung
A quick and practical guide to the @JsonFormat annotation in Jackson. ... STRING, pattern = "yyyy-MM-dd") public Date getCurrentDate() ...
Read more >
JsonFormat writes string even with NUMBER shape for a ...
NumberSerializer respects @JsonFormat annotation and if you set STRING shape it will produce JSON String instead of JSON Number .
Read more >
JsonFormat.Shape (Jackson-annotations 2.10.0 API)
Value that indicates that integer number type should be used (and not NUMBER_FLOAT ). STRING. public static final JsonFormat.Shape STRING. Value that indicates ......
Read more >
string — Understanding JSON Schema 2020-12 documentation
The format keyword allows for basic semantic identification of certain kinds of string values that are commonly used.
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
A string or number that's used to insert white space (including indentation, line break characters, etc.) into the output JSON string for readability...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found