Skip to content

Conversation

ilmari
Copy link
Contributor

@ilmari ilmari commented Sep 2, 2025

This matches the convert_blessed/allow_blessed behaviour of Cpanel::JSON::XS (since version 4.20, so also bump the requirement to that).

This matches the convert_blessed/allow_blessed behaviour of
Cpanel::JSON::XS (since version 4.20, so also bump the requirement to
that).
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the JSON encoding behavior for blessed objects that don't have a TO_JSON method or stringification overload. Instead of encoding them as strings, they are now encoded as null, which aligns with the convert_blessed/allow_blessed behavior in Cpanel::JSON::XS version 4.20+.

  • Updates the minimum required version of Cpanel::JSON::XS from 4.09 to 4.20
  • Modifies the encoding logic to check for stringification overload before falling back to string encoding
  • Adds comprehensive test coverage for objects with and without stringification overloads

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/Mojo/JSON.pm Core logic change to check for stringification overload and bump version requirement
t/mojo/json.t Adds test for object without stringification overload
t/mojo/json_xs.t Updates version requirement and adds comprehensive tests for both stringified and null-encoded objects
lib/Mojolicious/Command/version.pm Updates documentation to reflect new version requirement

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -5,12 +5,13 @@ use Carp qw(croak);
use Exporter qw(import);
use JSON::PP ();
use Mojo::Util qw(decode encode monkey_patch);
use overload ();
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The overload module is only used once in the file. Consider adding a comment explaining why it's imported at the top level rather than using it inline where needed, or move the usage to overload::Method($value, '""') directly without the import.

Suggested change
use overload ();

Copilot uses AI. Check for mistakes.

Comment on lines +253 to 254
return overload::Method($value, '""') ? _encode_string($value) : 'null' unless my $sub = $value->can('TO_JSON');
return _encode_value($value->$sub);
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This line combines multiple conditions and operations, making it difficult to read. Consider splitting this into separate conditional blocks for better clarity and maintainability.

Suggested change
return overload::Method($value, '""') ? _encode_string($value) : 'null' unless my $sub = $value->can('TO_JSON');
return _encode_value($value->$sub);
my $sub = $value->can('TO_JSON');
return _encode_value($value->$sub) if $sub;
if (overload::Method($value, '""')) {
return _encode_string($value);
}
return 'null';

Copilot uses AI. Check for mistakes.

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.

2 participants