Skip to content

refactor: replace JSON roundtrip with direct array-to-object conversion#34

Merged
wadakatu merged 2 commits intomainfrom
refactor/remove-json-roundtrip
Mar 17, 2026
Merged

refactor: replace JSON roundtrip with direct array-to-object conversion#34
wadakatu merged 2 commits intomainfrom
refactor/remove-json-roundtrip

Conversation

@wadakatu
Copy link
Collaborator

Summary

  • OpenApiResponseValidatorjson_encode()json_decode() の往復を廃止
  • 再帰的な toObject() ヘルパーで PHP 配列を直接 stdClass に変換するように変更
  • バリデーション時の一時的な JSON 文字列のメモリ割り当てを削減

Test plan

  • OpenApiResponseValidatorTest 全テスト通過
  • ResponseValidationTest (Integration) 全テスト通過
  • 全165テスト通過
  • PHPStan エラーなし
  • PHP-CS-Fixer 違反なし

…bject conversion

Replace json_encode() → json_decode() roundtrip in OpenApiResponseValidator
with a recursive toObject() helper that directly converts PHP arrays to
stdClass objects. This eliminates temporary JSON string allocations that
doubled memory usage for large response bodies and schemas during validation.
Verify that the toObject() helper produces structurally identical output
to json_decode(json_encode()) across 17 edge cases: scalars, empty arrays,
sequential/associative arrays, non-sequential integer keys, deeply nested
structures, and mixed types.
@wadakatu wadakatu force-pushed the refactor/remove-json-roundtrip branch from 1a5a672 to e9fc6cb Compare March 17, 2026 09:21
@wadakatu wadakatu self-assigned this Mar 17, 2026
@wadakatu wadakatu merged commit 6dcfb2c into main Mar 17, 2026
8 checks passed
@wadakatu wadakatu deleted the refactor/remove-json-roundtrip branch March 17, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant