RustyNova016 / musicbrainz_rs_nova

A wrapper around the musicbrainz API
MIT License
5 stars 3 forks source link

Serialize not working #29

Closed Holzhaus closed 2 months ago

Holzhaus commented 2 months ago

Thanks for maintaining this crate. I was planning to use this crate for fetching some data from musicbrainz, then serializing it to a file. However, at least for Releases, this is not working:

let mbid = "0008f765-032b-46cd-ab69-2220edab1837";
let release = MusicBrainzRelease::fetch()
        .id(&mbid)
        .with_artists()
        .with_recordings()
        .with_release_groups()
        .with_labels()
        .with_artist_credits()
        .with_aliases()
        .with_recording_level_relations()
        .with_work_relations()
        .with_work_level_relations()
        .with_artist_relations()
        .with_url_relations()
        .execute()
        .await
        .unwrap();
let release_toml = toml::to_string(&release).unwrap();
let release_after_roundtrip: Release = toml::from_str(&release_toml).unwrap();  // THIS FAILS
// called `Result::unwrap()` on an `Err` value: Error { inner: Error { inner: TomlError { message: "unknown variant `Normal`, expected one of `low`, `high`, `normal`, `unknown`, `none`", raw: ...

I suppose this is because some fields are renamed on deserialize, but not on serialize.

RustyNova016 commented 2 months ago

That's actually a problem I wanted to work on for a while, but I'm not sure how to implement it.

Either I keep the current API, and alias the renamed fields to deserialize both renamed and original Or I break the API and output the same data as MB sends.

I already asked the question once on the original repository without response so not sure what would be the best.

Holzhaus commented 2 months ago

Awesome, thanks for the quick fix!