Skip to content

Conversation

@JasonTheAdams
Copy link
Member

Follow up from: #28 (comment)

This adds support for serializing and unserializing DTOs to and from JSON. It introduces a WithJsonSerialization interface that all DTOs implement. This interfaces extends the built-in JsonSerializable interface so that json_encode() can be used on DTOs. It also adds a fromJson() static method so DTOs can be constructed from the same JSON data.

@JasonTheAdams JasonTheAdams requested a review from felixarntz July 28, 2025 15:53
@JasonTheAdams JasonTheAdams self-assigned this Jul 28, 2025
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams Some early thoughts here before I look more closely. FWIW, the feedback is probably the most crucial for us to discuss, to shape the remainder of the PR accordingly.

@JasonTheAdams JasonTheAdams requested a review from felixarntz July 28, 2025 21:35
@JasonTheAdams JasonTheAdams changed the title Adds JSON serialization and unserialization to DTOs Adds DTO array transformation and JSON serialization Jul 28, 2025
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams I think at a high level this looks great, but there are many things in this PR which shows the typical weaknesses of AI assisted code generation - such as overkill checks, or random patterns applied in some places but not others.

I left some of the concrete feedback below, let's discuss as needed, but most importantly decide for an approach and stick with it. This is the type of thing where AI generated code still requires a lot of revision.

@felixarntz felixarntz mentioned this pull request Jul 28, 2025
11 tasks
@JasonTheAdams
Copy link
Member Author

Pardon the force push. I accidentally added commits to the wrong branch. 😆

@JasonTheAdams JasonTheAdams requested a review from felixarntz July 29, 2025 22:21
@JasonTheAdams
Copy link
Member Author

This is ready for review, again, @felixarntz!

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams A few last points, but LGTM mostly.

],
],
'required' => ['message', 'finishReason', 'tokenCount'],
'required' => [self::KEY_MESSAGE, self::KEY_FINISH_REASON, self::KEY_TOKEN_COUNT],
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure every provider returns a token_count on an individual candidate? Should we leave that optional? Or would we prefer consistency and either set to 0 or try some estimation if it's not provided?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh, good question. How would token count be used downstream? Would folks be more likely to prefer to have something? Or would it be important to know that the model didn't provide one? The use case isn't clear enough for me to make a suggestion. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure yet myself 😆
Let's leave this for a later discussion, if it becomes more relevant.

@JasonTheAdams JasonTheAdams requested a review from felixarntz July 30, 2025 02:20
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Awesome stuff 🎉

@felixarntz felixarntz merged commit b0976a0 into trunk Jul 30, 2025
4 checks passed
@JasonTheAdams JasonTheAdams deleted the dto-serlialization branch July 30, 2025 16:48
@JasonTheAdams JasonTheAdams added this to the Finish the foundation milestone Aug 6, 2025
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.

3 participants