[PR #329] [MERGED] Replace build_json! with a JSON builder API #403

Closed
opened 2026-02-27 20:24:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/329
Author: @SabrinaJewson
Created: 6/15/2022
Status: Merged
Merged: 7/29/2022
Merged by: @marioortizmanero

Base: masterHead: json-builder


📝 Commits (7)

  • 3b017bf Replace build_json! with a JsonBuilder
  • b6a3db0 Replace json_builder() with JsonBuilder::new()
  • 4e3eb63 Rename JsonBuilder::[optional_]field to required and optional
  • ada3b84 Merge branch 'master' into json-builder
  • 7354a44 Format
  • fe07cc4 Use with_capacity in JsonBuilder
  • d70a737 Merge branch 'master' into json-builder

📊 Changes

3 files changed (+144 additions, -144 deletions)

View changed files

📝 rspotify-macros/src/lib.rs (+1 -79)
📝 src/clients/oauth.rs (+68 -65)
📝 src/util/mod.rs (+75 -0)

📄 Description

Description

Instead of:

build_json! {
    "a": b,
    optional "c": d,
}

we now use:

json_builder()
    .field("a", b)
    .optional_field("c", d)
    .build()

I would’ve used an array-based API like in #328 but that doesn’t really work well here because the field value types can be any type rather than just strings.

Dependencies

None.

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Please also list any relevant details for your test configuration

  • Test A: cargo test --features env-file

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/329 **Author:** [@SabrinaJewson](https://github.com/SabrinaJewson) **Created:** 6/15/2022 **Status:** ✅ Merged **Merged:** 7/29/2022 **Merged by:** [@marioortizmanero](https://github.com/marioortizmanero) **Base:** `master` ← **Head:** `json-builder` --- ### 📝 Commits (7) - [`3b017bf`](https://github.com/ramsayleung/rspotify/commit/3b017bf7537721d8e3c7f45976f8fef27a621672) Replace `build_json!` with a `JsonBuilder` - [`b6a3db0`](https://github.com/ramsayleung/rspotify/commit/b6a3db09268a2bcf644953acb397d6a26519663c) Replace `json_builder()` with `JsonBuilder::new()` - [`4e3eb63`](https://github.com/ramsayleung/rspotify/commit/4e3eb63d4322c1f546729d3c3e3e248f0df196e4) Rename `JsonBuilder::[optional_]field` to `required` and `optional` - [`ada3b84`](https://github.com/ramsayleung/rspotify/commit/ada3b8452f3646990e1de2de18e293c4fafcc5b9) Merge branch 'master' into json-builder - [`7354a44`](https://github.com/ramsayleung/rspotify/commit/7354a449b47478705b49dcfc156fc553723a9b05) Format - [`fe07cc4`](https://github.com/ramsayleung/rspotify/commit/fe07cc4045151c28c801be0861642fb470503d8c) Use `with_capacity` in `JsonBuilder` - [`d70a737`](https://github.com/ramsayleung/rspotify/commit/d70a737bf747da232d30565d43264ba42e84f2f7) Merge branch 'master' into json-builder ### 📊 Changes **3 files changed** (+144 additions, -144 deletions) <details> <summary>View changed files</summary> 📝 `rspotify-macros/src/lib.rs` (+1 -79) 📝 `src/clients/oauth.rs` (+68 -65) 📝 `src/util/mod.rs` (+75 -0) </details> ### 📄 Description ## Description Instead of: ```rs build_json! { "a": b, optional "c": d, } ``` we now use: ```rs json_builder() .field("a", b) .optional_field("c", d) .build() ``` I would’ve used an array-based API like in #328 but that doesn’t really work well here because the field value types can be any type rather than just strings. ## Dependencies None. ## How has this been tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Test A: `cargo test --features env-file` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:35 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#403
No description provided.