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.

MonthDaySerializer does not serialize objects into array

See original GitHub issue

Unlike YearMonthSerializer serialize objects as array " [2018, 5]", MonthDaySerializer serialize to “–03-02”

I notice document say, what should i do :

NOTE: unlike many other date/time type serializers, this serializer will only use Array notation if explicitly instructed to do so with JsonFormat (either directly or through per-type defaults) and NOT with global defaults.

I use org.springframework.boot:spring-boot-starter-web:2.1.3.RELEASE, com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8, com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8

application.yml

  jackson:
    serialization:
      INDENT_OUTPUT: false
      WRITE_DATES_AS_TIMESTAMPS: true

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
cowtowncodercommented, May 14, 2019

Ok finally got around to this one.

So: for some reason, original implementation defaulted to textual, not array-based, and since there is no way to distinguish “left as default” setting for use-timestamps from explicit, indication has to be done some other way. There are 2 main mechanisms: annotation with @JsonFormat and “config overrides”.

Former is

    static class Wrapper {
        @JsonFormat(shape = JsonFormat.Shape.ARRAY) // or NUMBER
        public MonthDay value;
    }

and config overrides something like

objectMapper.configOverride(MonthDay.class)
    .setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.ARRAY);

Now: these work, but it seems that deserialization part does NOT actually work at this point. So I’ll leave the issue open for now. I will add tests for serialization for 2.9, but deserialization fix probably needs to go in 2.10.0.

0reactions
cowtowncodercommented, Jul 17, 2019

Closing this, follow-up under #121.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Json array not serializing properly - Stack Overflow
I am trying to Json serialize and deserialize LocalDate array in my Java class but when i generate json schema for the web...
Read more >
MonthDaySerializer (Jackson datatype: JSR310 2.8.0 API)
NOTE: unlike many other date/time type serializers, this serializer will only use Array notation if explicitly instructed to do so with JsonFormat (either ......
Read more >
Serialization & Deserialization - Array of Objects - Java
In this session we will look at how to serialize and de- serialize an array of objects in Java. Please refer to my...
Read more >
serialize - Manual - PHP
serialize () handles all types, except the resource-type and some objects (see note below). You can even serialize() arrays that contain references to...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
If replacer is anything other than a function or an array (e.g. null or not provided), all properties of the object are included...
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