Skip to content

feat!: v5.0.0 release#69

Merged
usernane merged 10 commits into
devfrom
v5.0.0
Jun 10, 2026
Merged

feat!: v5.0.0 release#69
usernane merged 10 commits into
devfrom
v5.0.0

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Release v5.0.0 with breaking encoding changes, new attribute system, typed deserialization, and static configuration API.

Motivation

Addresses all open enhancement issues for the next major version. Closes #56, #58, #59, #60, #61, #63.

Changes

How to Test / Verify

composer install
composer test

All 186 tests pass with 438 assertions. Code coverage verified at 97.8%.

New examples can be run individually:

php examples/09-typed-deserialization.php
php examples/10-set-defaults.php

Breaking Changes and Migration Steps

  1. Associative arrays auto-detected as objectsaddArray() with associative arrays now encodes as JSON objects instead of discarding keys. Remove explicit $asObject = true if present (still works, just redundant).
  2. Getter-derived names normalized — with styles other than none, getter names like getName() now produce name (camel), name (snake) instead of Name. Style none is unchanged.
  3. Error suppression removed — getters that threw silently will now propagate errors. Getters requiring parameters are skipped via reflection.
  4. Global constants deprecatedJSON_STYLE, JSON_CASE, WF_VERBOSE trigger E_USER_DEPRECATED. Use Json::setDefaults() instead.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • The title of the pull request follows Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed)
  • I ran lint/cs-fixer (if applicable)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #56, #58, #59, #60, #61, #63

Ibrahim BinAlshikh added 10 commits June 10, 2026 23:25
…eter check

Remove set_error_handler(null)/restore_error_handler() and use
ReflectionMethod::getNumberOfRequiredParameters() to skip getters
that require arguments. Real errors now propagate instead of being
silently swallowed.

Closes #60
…nProperty] attribute

- Fix CaseConverter::toCamelCase() to lowercase first character of PascalCase input
- Add #[JsonProperty] attribute for explicit name override on getters and properties
- Add nameIsExplicit flag to Property to prevent style conversion on explicit names
- Check for #[JsonProperty] in objectToJson() for both getters and public properties

Style 'none' preserves backward-compatible PascalCase getter names.
Other styles now properly normalize (e.g. getName() -> 'name' in camel).

Closes #58
…ects

Add isIndexedArr() check in arrayToJsonString() to automatically treat
arrays with non-integer keys as JSON objects. The $asObject parameter
remains as an explicit override.

This aligns encoding behavior with json_encode() and prevents silent
data loss when associative arrays are passed without $asObject = true.

Updated test expectations to reflect the new correct behavior.

Closes #56
Add Json::setDefaults() and Json::resetDefaults() static methods for
application-wide configuration of style, case, and formatted output.

Static defaults take priority over global constants. Constructor
parameters override both. Global constants (JSON_STYLE, JSON_CASE,
WF_VERBOSE) now trigger E_USER_DEPRECATED notices when used.

Closes #61
Add Json::decodeAs() for deserializing JSON strings into typed objects.
Add JsonDeserializer class implementing the hydration algorithm:
  1. Static fromJSON(Json) factory method (custom deserialization)
  2. Constructor parameter reflection with recursive type resolution
  3. Setter/public property fallback for remaining keys

Add #[JsonType] attribute for annotating array-of-objects parameters
where PHP's type system is insufficient.

Add Json::setTypeMap() for runtime type mapping on decoded instances,
enabling typed returns from get() without attributes.

Closes #59
Restructure README to match the WebFiori ecosystem standard:
- Centered badges block (matching webfiori/collections style)
- Table of Contents
- composer require installation
- Contributing, License, Support, and Changelog sections
- Updated content to reflect all v5 features

Closes #63
…ures

Updated:
- 02-arrays.php: show auto-detection of associative arrays (no $asObject flag)
- 04-object-auto-mapping.php: show #[JsonProperty], #[JsonIgnore], normalization

Added:
- 08-json-property-attribute.php: explicit name override immune to style conversion
- 09-typed-deserialization.php: decodeAs(), nested hydration, #[JsonType], setTypeMap()
- 10-set-defaults.php: Json::setDefaults() and resetDefaults()
- Updated examples/README.md with new entries
Add JsonDeserializerTest covering:
- decodeAs() basic, nested, deep nesting
- fromJSON factory method support
- #[JsonType] attribute on constructor params and properties
- setTypeMap() runtime type registry
- setDefaults/resetDefaults
- #[JsonProperty] encoding behavior
- Associative array auto-detection
- Property nameIsExplicit flag
- CaseConverter camelCase fix

Add JsonCoverageTest covering:
- Setter-based hydration with typed params
- hydrateByJsonType edge cases
- Getter with required params skipped
- toJsonFile error paths
- addBoolean type guard

Coverage: 78% → 97.8% (remaining lines are constant-deprecation
branches, filesystem failure edges, and dead type guards)
@usernane usernane merged commit 2f773a1 into dev Jun 10, 2026
2 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.14894% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.05%. Comparing base (69855d3) to head (27a5dd3).
⚠️ Report is 26 commits behind head on dev.

Files with missing lines Patch % Lines
WebFiori/Json/JsonDeserializer.php 92.66% 8 Missing ⚠️
WebFiori/Json/Json.php 93.02% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev      #69      +/-   ##
============================================
- Coverage     98.97%   98.05%   -0.93%     
- Complexity      250      342      +92     
============================================
  Files             4        7       +3     
  Lines           587      771     +184     
============================================
+ Hits            581      756     +175     
- Misses            6       15       +9     
Flag Coverage Δ
php-8.3 98.05% <94.14%> (-0.93%) ⬇️
php-8.5 98.05% <94.14%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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