Skip to content

fix(abstractions): support double, byte array, and enum in scalar content serialization - #2238

Open
Hardik K (hardikkaurani) wants to merge 15 commits into
microsoft:mainfrom
hardikkaurani:fix/request-information-scalar-types-and-collections
Open

Hardik K (hardikkaurani) wants to merge 15 commits into
microsoft:mainfrom
hardikkaurani:fix/request-information-scalar-types-and-collections

Conversation

@hardikkaurani

@hardikkaurani Hardik K (hardikkaurani) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request addresses missing scalar type serialization and enhances collection handling in RequestInformation:

  1. Double Support in setContentFromScalar

    • Although SerializationWriter.writeDoubleValue is implemented across serialization writers, RequestInformation.setContentFromScalar previously lacked a branch for Double.class, resulting in RuntimeException: unknown type to serialize java.lang.Double when serializing double scalar values.
    • Added a Double.class branch delegating to writer.writeDoubleValue(null, (Double) value).
  2. Byte Array Support in setContentFromScalar

    • Added support for byte[].class, delegating to writer.writeByteArrayValue(null, (byte[]) value).
  3. Enum and ValuedEnum Support in setContentFromScalar

    • Added support for Enum<?> through writeEnumValue.
    • Added fallback string serialization for standalone ValuedEnum implementations.
  4. Span Request Type Inspection for Leading Nulls

    • Previously, collection serialization methods inspected only the first element (values[0]) when setting the telemetry span attribute com.microsoft.kiota.request.type.
    • If the first element was null, the request type attribute was omitted even when subsequent elements were valid.
    • Updated the implementation to resolve the first non-null element from arrays and iterables before setting the span attribute.
  5. Iterable Overloads for Collection Serialization

    • Added setContentFromScalarCollection(@Nonnull RequestAdapter, @Nonnull String, @Nonnull Iterable<T>) and setContentFromParsable(@Nonnull RequestAdapter, @Nonnull String, @Nonnull Iterable<T>) overloads to natively support Java Collection and Iterable types alongside arrays.

Verification

  • Spotless formatting: ./gradlew :components:abstractions:spotlessCheck — passed.
  • SpotBugs static analysis: ./gradlew :components:abstractions:spotbugsMain :components:abstractions:spotbugsTest — passed.
  • Full test suite: ./gradlew :components:abstractions:test --rerun-tasks — 39 tests passed, 0 failures, 0 errors, 0 skipped.

…mScalar

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…tFromScalar

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…setContentFromScalar

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…llection methods

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…FromScalarCollection

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…FromParsable

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ntentFromScalar

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…entFromScalar

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…n-null detection

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 5, 2026 20:21
Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

I've opened this PR to address missing scalar type serialization and improve collection handling in RequestInformation.

It adds support for Double, byte[], Enum<?>, and standalone ValuedEnum values in setContentFromScalar, fixes request-type span inspection when collections start with null elements, and adds Iterable<T> overloads for scalar and parsable collection serialization.

Regression tests have been added for these cases. Spotless, SpotBugs, and the full abstractions test suite all pass locally (39 tests).

Whenever you have a moment, I'd appreciate your review. Thank you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Telemetry scanning consumes one-shot iterables before serialization, dropping request values, while ordinary enums serialize to empty bodies instead of their names.

2 open issues

Review effort: Balanced

…d serialization

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…oads

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…alization

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Hardik K (hardikkaurani) commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

I've pushed updates across four commits to address the review findings related to iterable exhaustion and enum serialization:

  1. 9fd197f9 and 328ef2db (fix/test(abstractions)): Materialized non-Collection Iterable inputs once using toCollection() before telemetry inspection and serialization. This prevents single-use iterables, such as iterator wrappers or stream iterables, from being exhausted before reaching the serialization writer. Added regression tests covering both parsable and scalar collection overloads.

  2. 17f7626f and ae2d16d1 (fix/test(abstractions)): Updated writeEnumValue to delegate to writer.writeEnumValue for ValuedEnum instances and fall back to writer.writeStringValue(null, ((Enum<?>) value).name()) for standard Java enums, preventing empty serialization payloads. Added a regression test for ordinary enum serialization.

Verification:

  • ./gradlew :components:abstractions:spotlessCheck — clean.
  • ./gradlew :components:abstractions:spotbugsMain :components:abstractions:spotbugsTest — clean, 0 bugs.
  • ./gradlew :components:abstractions:test --rerun-tasks — all tests passing.

Whenever you have a moment, could you please approve the CI workflow run?

Thanks!

@baywet
Vincent Biret (baywet) requested a balanced review from Copilot November 9, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment on lines +421 to +427
@SuppressWarnings("unchecked")
private static <E extends Enum<E>> void writeEnumValue(
@Nonnull final SerializationWriter writer, @Nonnull final Object value) {
if (value instanceof ValuedEnum) {
writer.writeEnumValue(null, (E) value);
} else {
writer.writeStringValue(null, ((Enum<?>) value).name());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tightened writeEnumValue to accept @Nonnull final Enum<?> value, invoking value.name() directly for ordinary enums and delegating valued enums to a dedicated writeValuedEnumValue helper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed. The enum serialization helper accepts Enum<?> with the valued branch narrowed to <E extends Enum & ValuedEnum>, ensuring that only instances conforming to both Enum and ValuedEnum are dispatched to writeEnumValue.

…tion and tighten enum serialization

- Enforce non-null contract on Iterable collection overloads with Objects.requireNonNull.
- Fold request type span detection into single-pass materialization for non-Collection iterables, avoiding redundant traversals.
- Tighten writeEnumValue helper to accept Enum<?> and avoid unbounded generic casts on Object.
- Add regression tests for single-pass leading null handling and null iterable contracts.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Vincent Biret (@baywet) Pushed an update addressing the latest review feedback:

  • Single-pass iterable materialization & telemetry: Folded request-type detection directly into the materialization loop in prepareCollectionPayload(). Non-Collection iterables are now traversed only once to both populate the backing list and set the span attribute from the first non-null element.
  • Null validation: Enforced the @Nonnull contract upfront with Objects.requireNonNull on both Iterable collection overloads, adding corresponding regression tests.
  • Enum serialization: Tightened writeEnumValue to take Enum<?> directly, calling value.name() for ordinary enums and delegating valued enums to a dedicated helper.

Spotless, SpotBugs (spotbugsMain & spotbugsTest), and the full test suite across all components are passing cleanly. Ready for another look when you get a chance!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The leading-null tests would pass with the old implementation, leaving first-non-null request-type telemetry unverified for both collection serialization methods, including iterable paths.

2 open issues
4 resolved since last review

Review effort: Balanced

if (values == null || span == null) return;
for (final T value : values) {
if (value != null) {
setRequestType(value, span);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed. Added assertions using mocked telemetry spans verifying that com.microsoft.kiota.request.type matches the first non-null element across all collection paths: arrays, standard Iterable/Collection instances, and single-use iterables for both parsable and scalar payloads.

…g-null collection span telemetry

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Vincent Biret (@baywet) Pushed an update addressing the review findings: narrowed the valued enum helper bound to <E extends Enum & ValuedEnum> to enforce type safety without unbounded casts, and added span assertions across arrays, Iterable collections, and single-use iterables verifying that com.microsoft.kiota.request.type records the first non-null element. All tests, Spotless, and SpotBugs are passing locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants