Skip to content

Commit 826c1d7

Browse files
committed
switched from simd-json to serde_json
1 parent f67d72a commit 826c1d7

File tree

34 files changed

+129
-130
lines changed

34 files changed

+129
-130
lines changed

CHANGELOG.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
* Release notes are available on
44
[GitHub](https://github.com/leontoeides/google_maps/releases).
55

6+
# 3.8.2
7+
8+
* 2025-04-10: Reverted back to `serde_json` from `simd-json`.
9+
10+
There were issues with some Google Maps API JSON responses. They failed
11+
validation according to [jsonlint.com](https://jsonlint.com/). `simd-json` was
12+
having issues with this JSON.
13+
14+
`serde_json` seems to be more robust in handling (presumably) invalid JSON.
15+
16+
* 2025-04-10: Ensured that all `serde` `skip_serializing_if` attributes have a
17+
matching `default` attribute.
18+
619
# 3.8.1
720

8-
* 2024-01-10: A debug `println!` was accidentally left in the `Client`
21+
* 2025-01-10: A debug `println!` was accidentally left in the `Client`
922
`get_request` method. This has been removed.
1023

1124
# 3.8.0
@@ -16,7 +29,7 @@
1629
`structs`. However, I don't believe most crate end-users will notice a
1730
difference.
1831

19-
* 2024-01-10: Implemented Google Maps [Address Validation
32+
* 2025-01-10: Implemented Google Maps [Address Validation
2033
API](https://developers.google.com/maps/documentation/address-validation).
2134
Basic example:
2235

Cargo.toml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "google_maps"
3-
version = "3.8.1"
3+
version = "3.8.2"
44
authors = ["Dylan Bowker <dylan.bowker@arkiteq.io>"]
55
edition = "2021"
66
categories = ["api-bindings"]
@@ -39,10 +39,6 @@ default = [
3939

4040
# rust_decimal default features:
4141
"decimal-serde",
42-
43-
# simd-json default features:
44-
"simd-json-beef",
45-
"simd-json-known-key",
4642
]
4743
# google_maps features:
4844
autocomplete = []
@@ -97,27 +93,16 @@ decimal-serde-arbitrary-precision = ["rust_decimal/serde-arbitrary-precision"]
9793
decimal-serde-with-float = ["rust_decimal/serde-with-float"]
9894
decimal-serde-with-str = ["rust_decimal/serde-with-str"]
9995
decimal-serde-with-arbitrary-precision = ["rust_decimal/serde-with-arbitrary-precision"]
100-
# simd-json features:
101-
simd-json-arraybackend = ["simd-json/arraybackend"]
102-
simd-json-value-no-dup-keys = ["simd-json/value-no-dup-keys"]
103-
simd-json-128bit = ["simd-json/128bit"]
104-
simd-json-beef = ["simd-json/beef"]
105-
simd-json-known-key = ["simd-json/known-key"]
106-
simd-json-swar-number-parsing = ["simd-json/swar-number-parsing"]
107-
simd-json-approx-number-parsing = ["simd-json/approx-number-parsing"]
108-
simd-json-serde_impl = ["simd-json/serde_impl"]
109-
simd-json-alloc = ["simd-json/alloc"]
110-
simd-json-hints = ["simd-json/hints"]
111-
simd-json-runtime-detection = ["simd-json/runtime-detection"]
11296

11397
[dependencies]
11498
miette = "7.5"
11599
percent-encoding = "2.3"
116100
phf = { version = "0.11", features = ["macros"] }
117-
rust_decimal = { version = "1", features = ["serde"] }
101+
rust_decimal = { version = "1", features = ["serde", "serde-float"] }
118102
rust_decimal_macros = "1"
119103
serde = { version = "1.0", features = ["derive"] }
120-
simd-json = "0.14"
104+
# simd-json = "0.14"
105+
serde_json = "1.0"
121106
thiserror = "2.0"
122107
tracing = { version = "0.1", features = ["log"] }
123108

src/address_validation/provide_validation_feedback/request/request_body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ impl crate::traits::RequestBody for crate::address_validation::provide_validatio
88
/// convert the above defined `RequestBody` struct into JSON for submission
99
/// to Google Maps.
1010
fn request_body(&self) -> Result<String, crate::Error> {
11-
Ok(simd_json::serde::to_string(&RequestQuery::from(self))?)
11+
Ok(serde_json::to_string(&RequestQuery::from(self))?)
1212
} // fn
1313
} // impl

src/address_validation/validate_address/request/request_body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ impl crate::traits::RequestBody for crate::address_validation::validate_address:
1010
/// In this case, we'll be converting the `RequestQuery` struct into a JSON
1111
/// object which will be submitted inside the HTTP request's body.
1212
fn request_body(&self) -> Result<String, crate::Error> {
13-
Ok(simd_json::serde::to_string(&RequestQuery::from(self))?)
13+
Ok(serde_json::to_string(&RequestQuery::from(self))?)
1414
} // fn
1515
} // impl

src/client/get_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl crate::Client {
6969
Ok(request) => match self.reqwest_client.execute(request).await {
7070
Ok(response) => if response.status().is_success() {
7171
match response.text().await.map(String::into_bytes) {
72-
Ok(mut bytes) => match simd_json::serde::from_slice::<RSP>(&mut bytes) {
72+
Ok(bytes) => match serde_json::from_slice::<RSP>(&bytes) {
7373
Ok(deserialized) => {
7474
let result: Result<RSP, ERR> = deserialized.into();
7575
if let Err(error) = &result {

src/client/post_request.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ impl crate::Client {
1919
/// parameters in the request conflict with one another, or the request
2020
/// parameters are set in a way that's incompatible.
2121
///
22-
/// For example, Google Maps Address Validation API will refuse a
23-
/// `PostalAddress` greater than 280 characters. This will cause a
22+
/// For example, Google Maps Address Validation API will refuse a
23+
/// `PostalAddress` greater than 280 characters. This will cause a
2424
/// validation failure.
2525
///
2626
/// * The HTTP client cannot make a connection to the Google Maps API
@@ -77,7 +77,7 @@ impl crate::Client {
7777
Ok(request) => match self.reqwest_client.execute(request).await {
7878
Ok(response) => if response.status().is_success() {
7979
match response.text().await.map(String::into_bytes) {
80-
Ok(mut bytes) => match simd_json::serde::from_slice::<RSP>(&mut bytes) {
80+
Ok(bytes) => match serde_json::from_slice::<RSP>(&bytes) {
8181
Ok(deserialized) => {
8282
let result: Result<RSP, ERR> = deserialized.into();
8383
if let Err(error) = &result {
@@ -100,7 +100,7 @@ impl crate::Client {
100100
} // match
101101
} else {
102102
tracing::error!(
103-
"Google Maps API HTTP request was unsuccessful: {status}",
103+
"Google Maps API HTTP request unsuccessful: {status}",
104104
status = response.status(),
105105
);
106106
Err(Error::from(response.status()))

src/directions/response/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,32 @@ pub struct Response {
8585
// -----------------------------------------------------------------------------
8686

8787
impl std::convert::TryFrom<String> for Response {
88-
type Error = simd_json::Error;
88+
type Error = serde_json::Error;
8989
/// Convert a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
9090
/// `String` response into a `Response` struct.
9191
fn try_from(s: String) -> Result<Self, Self::Error> {
92-
simd_json::serde::from_slice(&mut s.into_bytes())
92+
serde_json::from_slice(&mut s.into_bytes())
9393
} // fn
9494
} // impl
9595

9696
// -----------------------------------------------------------------------------
9797

9898
impl std::str::FromStr for Response {
99-
type Err = simd_json::Error;
99+
type Err = serde_json::Error;
100100
/// Converts a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
101101
/// `&str` response into a `Response` struct.
102102
///
103103
/// # Notes
104104
///
105105
/// * It's recommended to use the implemented `TryFrom` trait instead.
106106
///
107-
/// * The [simd_json](https://crates.io/crates/simd-json)'s `from_str`
107+
/// * The [serde_json](https://crates.io/crates/simd-json)'s `from_str`
108108
/// function implementation is unsafe and it's `from_slice` function
109109
/// requires a mutable reference. Therefore this trait clones the `&str`
110110
/// into a `String` to give `from_slice` mutable access to the string.
111111
fn from_str(s: &str) -> Result<Self, Self::Err> {
112112
let mut bytes = s.to_string().into_bytes();
113-
simd_json::serde::from_slice(&mut bytes)
113+
serde_json::from_slice(&mut bytes)
114114
} // fn
115115
} // impl
116116

src/directions/response/transit_fare.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ use crate::directions::response::transit_currency::TransitCurrency;
44
use rust_decimal::Decimal;
55
use serde::{Deserialize, Serialize};
66

7+
// -----------------------------------------------------------------------------
8+
//
79
/// If present, contains the total fare (that is, the total ticket costs) on
810
/// this route. This property is only returned for transit requests and only for
911
/// routes where fare information is available for all transit legs.
10-
1112
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
1213
pub struct TransitFare {
1314
/// An [ISO 4217 currency code](https://en.wikipedia.org/wiki/ISO_4217)
1415
/// indicating the currency that the amount is expressed in.
1516
pub currency: TransitCurrency,
17+
1618
/// The total fare amount, formatted in the requested language.
1719
pub text: String,
20+
1821
/// The total fare amount, in the currency specified above.
22+
#[serde(with = "rust_decimal::serde::float")]
1923
pub value: Decimal,
2024
} // struct

src/distance_matrix/response/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,32 @@ pub struct Response {
6060
// -----------------------------------------------------------------------------
6161

6262
impl std::convert::TryFrom<String> for Response {
63-
type Error = simd_json::Error;
63+
type Error = serde_json::Error;
6464
/// Convert a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
6565
/// `String` response into a `Response` struct.
6666
fn try_from(s: String) -> Result<Self, Self::Error> {
67-
simd_json::serde::from_slice(&mut s.into_bytes())
67+
serde_json::from_slice(&mut s.into_bytes())
6868
} // fn
6969
} // impl
7070

7171
// -----------------------------------------------------------------------------
7272

7373
impl std::str::FromStr for Response {
74-
type Err = simd_json::Error;
74+
type Err = serde_json::Error;
7575
/// Converts a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
7676
/// `&str` response into a `Response` struct.
7777
///
7878
/// # Notes
7979
///
8080
/// * It's recommended to use the implemented `TryFrom` trait instead.
8181
///
82-
/// * The [simd_json](https://crates.io/crates/simd-json)'s `from_str`
82+
/// * The [serde_json](https://crates.io/crates/simd-json)'s `from_str`
8383
/// function implementation is unsafe and it's `from_slice` function
8484
/// requires a mutable reference. Therefore this trait clones the `&str`
8585
/// into a `String` to give `from_slice` mutable access to the string.
8686
fn from_str(s: &str) -> Result<Self, Self::Err> {
8787
let mut bytes = s.to_string().into_bytes();
88-
simd_json::serde::from_slice(&mut bytes)
88+
serde_json::from_slice(&mut bytes)
8989
} // fn
9090
} // impl
9191

src/elevation/response/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,32 @@ pub struct Response {
4141
// -----------------------------------------------------------------------------
4242

4343
impl std::convert::TryFrom<String> for Response {
44-
type Error = simd_json::Error;
44+
type Error = serde_json::Error;
4545
/// Convert a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
4646
/// `String` response into a `Response` struct.
4747
fn try_from(s: String) -> Result<Self, Self::Error> {
48-
simd_json::serde::from_slice(&mut s.into_bytes())
48+
serde_json::from_slice(&mut s.into_bytes())
4949
} // fn
5050
} // impl
5151

5252
// -----------------------------------------------------------------------------
5353

5454
impl std::str::FromStr for Response {
55-
type Err = simd_json::Error;
55+
type Err = serde_json::Error;
5656
/// Converts a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
5757
/// `&str` response into a `Response` struct.
5858
///
5959
/// # Notes
6060
///
6161
/// * It's recommended to use the implemented `TryFrom` trait instead.
6262
///
63-
/// * The [simd_json](https://crates.io/crates/simd-json)'s `from_str`
63+
/// * The [serde_json](https://crates.io/crates/simd-json)'s `from_str`
6464
/// function implementation is unsafe and it's `from_slice` function
6565
/// requires a mutable reference. Therefore this trait clones the `&str`
6666
/// into a `String` to give `from_slice` mutable access to the string.
6767
fn from_str(s: &str) -> Result<Self, Self::Err> {
6868
let mut bytes = s.to_string().into_bytes();
69-
simd_json::serde::from_slice(&mut bytes)
69+
serde_json::from_slice(&mut bytes)
7070
} // fn
7171
} // impl
7272

src/error.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub enum Error {
114114
/// the JSON response if available.
115115
#[error(transparent)]
116116
#[diagnostic(code(google_maps::json))]
117-
Json(#[from] simd_json::Error),
117+
Json(#[from] serde_json::Error),
118118

119119
/// Error originating from the [polyline](https://crates.io/crates/polyline)
120120
/// crate.
@@ -245,12 +245,7 @@ impl ClassifiableError<'_, Self> for Error {
245245
ClassifiedError::Permanent(self)
246246
}, // Http
247247

248-
Self::Json(json_error) =>
249-
if json_error.classify().is_transient() {
250-
ClassifiedError::Transient(self)
251-
} else {
252-
ClassifiedError::Permanent(self)
253-
}, // Http
248+
Self::Json(_json_error) => ClassifiedError::Permanent(self),
254249

255250
#[cfg(feature = "polyline")]
256251
Self::Polyline(_polyline_error) => ClassifiedError::Permanent(self),

src/geocoding/response/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,32 @@ pub struct Response {
4444
// -----------------------------------------------------------------------------
4545

4646
impl std::convert::TryFrom<String> for Response {
47-
type Error = simd_json::Error;
47+
type Error = serde_json::Error;
4848
/// Convert a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
4949
/// `String` response into a `Response` struct.
5050
fn try_from(s: String) -> Result<Self, Self::Error> {
51-
simd_json::serde::from_slice(&mut s.into_bytes())
51+
serde_json::from_slice(&mut s.into_bytes())
5252
} // fn
5353
} // impl
5454

5555
// -----------------------------------------------------------------------------
5656

5757
impl std::str::FromStr for Response {
58-
type Err = simd_json::Error;
58+
type Err = serde_json::Error;
5959
/// Converts a Google Maps API [JSON](https://en.wikipedia.org/wiki/JSON)
6060
/// `&str` response into a `Response` struct.
6161
///
6262
/// # Notes
6363
///
6464
/// * It's recommended to use the implemented `TryFrom` trait instead.
6565
///
66-
/// * The [simd_json](https://crates.io/crates/simd-json)'s `from_str`
66+
/// * The [serde_json](https://crates.io/crates/simd-json)'s `from_str`
6767
/// function implementation is unsafe and it's `from_slice` function
6868
/// requires a mutable reference. Therefore this trait clones the `&str`
6969
/// into a `String` to give `from_slice` mutable access to the string.
7070
fn from_str(s: &str) -> Result<Self, Self::Err> {
7171
let mut bytes = s.to_string().into_bytes();
72-
simd_json::serde::from_slice(&mut bytes)
72+
serde_json::from_slice(&mut bytes)
7373
} // fn
7474
} // impl
7575

src/geolocation/response/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ pub struct Response {
2727
} // struct
2828

2929
impl std::str::FromStr for Response {
30-
type Err = simd_json::Error;
30+
type Err = serde_json::Error;
3131
/// Parse a Google Maps Geolocation API JSON `String` into a `Response`
3232
/// usable `Response` struct.
33-
fn from_str(s: &str) -> Result<Self, simd_json::Error> {
33+
fn from_str(s: &str) -> Result<Self, serde_json::Error> {
3434
let mut bytes = s.to_string().into_bytes();
35-
simd_json::serde::from_slice(&mut bytes)
35+
serde_json::from_slice(&mut bytes)
3636
}
3737
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
clippy::missing_errors_doc,
432432
clippy::module_name_repetitions,
433433
clippy::multiple_crate_versions,
434-
clippy::negative_feature_names, // suppress clippy warning re: `simd_json` crate
434+
clippy::negative_feature_names, // suppress clippy warning re: `serde_json` crate
435435
clippy::too_long_first_doc_paragraph, // bah!
436436
clippy::too_many_lines
437437
)]

src/places/place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ pub struct Place {
322322
// -----------------------------------------------------------------------------
323323

324324
impl std::str::FromStr for Place {
325-
type Err = simd_json::Error;
325+
type Err = serde_json::Error;
326326
/// Parse a Google Maps Places API JSON response into a usable `Place`
327327
/// struct.
328-
fn from_str(s: &str) -> Result<Self, simd_json::Error> {
328+
fn from_str(s: &str) -> Result<Self, serde_json::Error> {
329329
let mut bytes = s.to_string().into_bytes();
330-
simd_json::serde::from_slice(&mut bytes)
330+
serde_json::from_slice(&mut bytes)
331331
} // fn from_str
332332
} // impl FromStr

src/places/place_autocomplete/response/matched_substring.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ pub struct MatchedSubstring {
2424
// -----------------------------------------------------------------------------
2525

2626
impl std::str::FromStr for MatchedSubstring {
27-
type Err = simd_json::Error;
27+
type Err = serde_json::Error;
2828
/// Parse a Google Maps Places API _Place Autocomplete_ JSON
2929
/// `MatchedSubstring` response into a usable `MatchedSubstring` struct.
30-
fn from_str(s: &str) -> Result<Self, simd_json::Error> {
30+
fn from_str(s: &str) -> Result<Self, serde_json::Error> {
3131
let mut bytes = s.to_string().into_bytes();
32-
simd_json::serde::from_slice(&mut bytes)
32+
serde_json::from_slice(&mut bytes)
3333
} // fn from_str
3434
} // impl FromStr

0 commit comments

Comments
 (0)