Skip to content

Commit 2fd160d

Browse files
committed
refactor: simplify wrap_value by removing redundant empty map check
Remove unnecessary empty map check in wrap_value function. The check was replacing an empty Map with Map::new(), which is functionally identical since both produce empty JSON objects when serialized. The simplified version: - Reduces code from 18 to 10 lines - Maintains identical behavior for all inputs - Passes all existing tests including property tests - Produces no clippy warnings Fixes #47
1 parent 9143a29 commit 2fd160d

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/generic/builders/generic_builder.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,13 @@ fn wrap_claims(claims: HashMap<String, Value>) -> Value {
170170
// A `serde_json::Value` representing the wrapped value
171171
fn wrap_value(value: Value) -> Value {
172172
match value {
173-
// If the value is an object, check if it's empty
173+
// Recursively wrap each key-value pair in the map
174174
Value::Object(map) => {
175-
if map.is_empty() {
176-
// Wrap empty map as an empty JSON object
177-
Value::Object(Map::new())
178-
} else {
179-
// Recursively wrap each key-value pair in the map
180-
Value::Object(map.into_iter().map(|(k, v)| (k, wrap_value(v))).collect())
181-
}
175+
Value::Object(map.into_iter().map(|(k, v)| (k, wrap_value(v))).collect())
182176
}
183-
// If the value is an array, recursively wrap each element
177+
// Recursively wrap each element in the array
184178
Value::Array(arr) => Value::Array(arr.into_iter().map(wrap_value).collect()),
185-
// If the value is null, return it as is
186-
Value::Null => Value::Null,
187-
// For primitive values, return them as is
179+
// For null and primitive values, return them as is
188180
other => other,
189181
}
190182
}

0 commit comments

Comments
 (0)