leontoeides / google_maps

An unofficial Google Maps Platform client library for the Rust programming language.
https://crates.io/crates/google_maps
Apache License 2.0
58 stars 25 forks source link

Roundtrip serialisation does not work for directions::response::Response #30

Closed xyres137 closed 2 weeks ago

xyres137 commented 2 weeks ago

Hi, I have noticed that roundtrip serialisation does not work for directions::response::Response.

Steps to reproduce:

Executing this script:

#[tokio::main]
async fn main() {
    let client = GoogleMapsClient::try_new("API_KEY").unwrap();

    let response = client
        .directions(
            Location::from_address("London, UK"),
            Location::from_address("Manchester, UK"),
        )
        .with_travel_mode(TravelMode::Driving)
        .execute()
        .await.unwrap();

    let serialised_response = serde_json::to_string(&response).unwrap();
    let deserialised_response: Response = serde_json::from_str(&serialised_response).unwrap();

    println!("{}", &deserialised_response.status);
}

we get the following error:

 Error("Google Maps Directions API client: `Ok` is not a valid geocoder status code. Valid codes are `OK`, and `ZERO_RESULTS`.", line: 1, column: 46)

which shows the culprit is the serialisation/deserialisation of status enums.

System configuration:

google_maps = "3.7.1"
serde_json = "1.0.132"
cargo 1.79.0
leontoeides commented 2 weeks ago

Apologies for the error and the long response time. This should be corrected now. Unfortunately I do not have the bandwidth to test. Please let me know how it goes.

xyres137 commented 2 weeks ago

Hi @leontoeides, and thanks very much for the prompt response on this. I confirm that the fix works, if applied also to one more enum, see PR ⬆️.

leontoeides commented 2 weeks ago

I've applied your PR. Second time's the charm? Let me know how it goes