brick / date-time

Date and time library for PHP
MIT License
337 stars 30 forks source link

Implement JsonSerializable for all value classes #18

Closed kagmole closed 4 years ago

kagmole commented 5 years ago

It would be nice if value classes had a support for JSON serialization into ISO strings by implementing JsonSerializable.

Most, if not all, jsonSerialize implementations would just be proxies of __toString.

So my questions are:

  1. Do you consider this to be in the scope of the library?
  2. If yes, are you accepting pull-requests?
BenMorel commented 5 years ago

Hi,

  1. Sure, this is definitely in scope. Of course when decoding JSON, you'll just get a string, though.
  2. PRs welcome!
kagmole commented 5 years ago

Yes, deserialization will require some business logic to get back the value class from the string, as usual I would say. :^)

It will follow the serialization as if one was using Jackson.

https://fasterxml.github.io/jackson-modules-java8/javadoc/datetime/2.9/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.html

While it is not part of JSR-310, it is quite common that Java JSON API's return dates in ISO formats using Jackson.

kagmole commented 4 years ago

Closing the issue as it was resolved with #19.