Skip to content

Serde Behavior #629

@benhaney

Description

@benhaney

This is a summary and continuation of benhaney/Jsonrs#26, by @filmor's request.

It was recently suggested to me that Jsonrs should switch to using Rustler's new Serde integration as its backend, which I'm very excited to do. But before I can, I need to make sure that Rustler's use of Serde can match what Jsonrs expects, so I don't break backwards compatibility. This issue represents the problems I've seen so far.

In approximate order of importance:

  1. Rustler explicitly serializes the atoms :ok and :error into the strings "Ok" and "Err", inconsistent with the serialization of all other atoms. This is by far the biggest issue and should also be the easiest to fix.
  2. I handle encoding Elixir's Decimal struct at the Rust layer, so I will either need that same support in Rustler (sorry!) or a way to pass some custom struct encoding functions to the deserializer. I think the former would be a lot easier if it isn't too objectionable (and I'm happy to contribute the implementation I already have), but I recognize that it would be a bit weird for a general purpose NIF library like Rustler to specially handle struct encoding of specific Elixir packages, even if they're very popular.
  3. I noticed some tests related to error tuples failed when testing Jsonrs using Rustler's Serde integration. An example:
     code:  Jsonrs.decode("invalid") === {:error, "expected value at line 1 column 1"}
     left:  {:error, "SerializationError(\"expected value at line 1 column 1\")"}
     right: {:error, "expected value at line 1 column 1"}
    
    This isn't necessarily something that Rustler should deal with, it just wasn't immediately obvious to me why some of these changed and I need to make a note to look into why it happened at all and what I might need to do in Jsonrs to hammer the errors back into the format I was seeing before. I'm not terribly against changing error strings, but it would technically be a breaking change for Jsonrs so I'd like to avoid it where reasonable. If anyone's immediately aware of what changed here, it would save me the investigation.

I think that's all I've found so far. Let me know your thoughts and what I can do to help with any of this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions