feat: support composed types in write_object_value - #88
Conversation
Update write_object_value to accept variadic additional_values_to_merge for intersection type serialization and handle ComposedTypeWrapper by serializing directly into the current writer instead of a temp. Refactor write_collection_of_object_values to create its own temp writers instead of delegating to write_object_value, since the nil-key path now serializes into self.
There was a problem hiding this comment.
Pull request overview
This PR updates the JSON serialization writer to properly support composed types (union/intersection wrappers) by allowing write_object_value to merge multiple Parsable instances and to serialize nil-key object values directly into the current writer (instead of via a temporary writer). It also refactors collection serialization to avoid contaminating the parent writer under the new nil-key behavior, and adds dedicated specs covering these composed-type scenarios.
Changes:
- Extend
write_object_valueto accept variadicadditional_values_to_mergeand merge them during serialization (intersection support). - Change
write_object_value(nil, ...)behavior to serialize directly into the current writer (enabling composed wrappers to work without needing to handle a returned temp writer). - Refactor
write_collection_of_object_valuesto always serialize items into per-item temp writers, returning them whenkeyisnil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/microsoft_kiota_serialization_json/json_serialization_writer.rb | Implements composed-type support in write_object_value and refactors object-collection serialization to use temp writers. |
| spec/json_serialization_writer_composed_type_spec.rb | Adds coverage for composed types (union/intersection) and updated nil-key serialization semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Delegate to write_object_value instead of creating temp JsonSerializationWriter instances directly, aligning with how other Kiota language implementations handle collection serialization. Also removes redundant require and adds ComposedTypeWrapper polyfill for the test suite.
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thank you for making the changes!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
lib/microsoft_kiota_serialization_json/json_serialization_writer.rb:155
- The keyed path temporarily writes each element into
@writer[key]and then deletes it to capture the value. This mutates the parent writer during serialization; if an element raises duringserialize,@writercan be left in a partially mutated state (and any prior@writer[key]value is overwritten). It’s also extra work compared to building each element in an isolated temp writer.
@writer[key] = values.map do |v|
write_object_value(key, v)
@writer.delete(key)
end
Centralizes temp writer creation into a private helper shared by write_object_value and write_collection_of_object_values, eliminating the fragile write-then-delete pattern from the keyed collection path.
|
Should be ready for final review. |
|
Andrea Peruffo (@andreaTP) I'm not sure why but the abstractions dependency update is not coming through dependabot. Can you also add that as part of your PR please? |
Requires v0.16.0 which includes ComposedTypeWrapper, ParseNodeHelper, and the updated write_object_value signature needed for composed type support. Removes the test polyfill that was standing in for these.
|
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thank you for making the changes!
|
Let me know when this one is released so that I'll unblock the kiota PR 🙏 |



Based on: microsoft/kiota-ruby#106
Update
write_object_valueto accept variadic additional_values_to_merge for intersection type serialization and handle ComposedTypeWrapper by serializing directly into the current writer instead of a temp.Refactor write_collection_of_object_values to create its own temp writers instead of delegating to write_object_value, since the nil-key path now serializes into self.