[Firebase AI] Add simplified object generation#1423
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces GenerateObjectAsync to the Firebase AI SDK, enabling simplified object generation from model responses. It includes a new GenerateObjectResponse<T> struct and a SerializationHelpers utility class to handle JSON deserialization via reflection or the IFirebaseDeserializable interface. The review identified several critical issues: the GenerateObjectResponse struct is vulnerable to NullReferenceException if initialized via the default constructor, the deserialization logic fails when casting null results to value types, Enum.Parse lacks robustness for numeric JSON values, the list deserialization logic does not support generic collection interfaces, and the logging in the serialization helper is overly verbose for production.
Description
Add logic to allow easier object generation with GenerateObjectAsync on GenerativeModel. Add the IFirebaseDeserializable interface, to allow users to define their own method of deserialization if the reflection logic won't work for their needs.
Testing
Running test locally. Proper automated tests will be included in a future PR, as part of another feature.
Type of Change
Place an
xthe applicable box: