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

Feature Request: Serialize IPAddress #1444

Closed
EmperorArthur opened this issue Dec 3, 2020 · 3 comments
Closed

Feature Request: Serialize IPAddress #1444

EmperorArthur opened this issue Dec 3, 2020 · 3 comments
Milestone

Comments

@EmperorArthur
Copy link

Currently compilation fails if ArdunioJson attempts to serialize an IPAddress object.

On the surface, this makes sense because it is not something which can be directly converted to JSON. However, Serial.print(..) explicitly works, so it catches users off gaurd.

Code to convert IPAddress to a string, which can be serialized.

out = String(address[0]) + "." + String(address[1]) + "." + String(address[2]) + "." + String(address[3])
@bblanchon
Copy link
Owner

We can make this feature more general by including any Printable type.

@EmperorArthur
Copy link
Author

EmperorArthur commented Dec 4, 2020

That would be great!

Hmm, Printable types implement printTo(Print& p) const. The good news, is that it looks like you can get away with just implementing size_t write(uint8_t c), on a subclass, though you could also overwrite size_t write(const uint8_t *buffer, size_t size) for more efficient operation. Then again, I'm speaking to someone who has much greater experience with the code than I do, as your "PrintWriter" shows.

@bblanchon bblanchon added this to the v6.18 milestone Mar 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2021
@bblanchon
Copy link
Owner

Feature published in ArduinoJson 6.18.0

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

No branches or pull requests

2 participants