Repository navigation
fix(abstractions): support double, byte array, and enum in scalar content serialization - #2238
Conversation
…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>
|
I've opened this PR to address missing scalar type serialization and improve collection handling in It adds support for 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! |
…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>
|
I've pushed updates across four commits to address the review findings related to iterable exhaustion and enum serialization:
Verification:
Whenever you have a moment, could you please approve the CI workflow run? Thanks! |
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
5 open issues
toCollection(values)may fully materialize the iterable, and then… · NewtoCollectioncan returnnull, but the callers pass its result into… · New Serialize ordinary enums using their names Materialize one-shot iterables before telemetry and serialization This helper relies on an unchecked cast(E) valuewhile acceptingObject value, which makes the… · New
Review effort: Lite
| @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()); |
There was a problem hiding this comment.
Tightened writeEnumValue to accept @Nonnull final Enum<?> value, invoking value.name() directly for ordinary enums and delegating valued enums to a dedicated writeValuedEnumValue helper.
There was a problem hiding this comment.
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>
|
Vincent Biret (@baywet) Pushed an update addressing the latest review feedback:
Spotless, SpotBugs ( |
There was a problem hiding this comment.
🟡 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); |
There was a problem hiding this comment.
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>
|
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. |


Summary of Changes
This pull request addresses missing scalar type serialization and enhances collection handling in
RequestInformation:Double Support in
setContentFromScalarSerializationWriter.writeDoubleValueis implemented across serialization writers,RequestInformation.setContentFromScalarpreviously lacked a branch forDouble.class, resulting inRuntimeException: unknown type to serialize java.lang.Doublewhen serializing double scalar values.Double.classbranch delegating towriter.writeDoubleValue(null, (Double) value).Byte Array Support in
setContentFromScalarbyte[].class, delegating towriter.writeByteArrayValue(null, (byte[]) value).Enum and
ValuedEnumSupport insetContentFromScalarEnum<?>throughwriteEnumValue.ValuedEnumimplementations.Span Request Type Inspection for Leading Nulls
values[0]) when setting the telemetry span attributecom.microsoft.kiota.request.type.null, the request type attribute was omitted even when subsequent elements were valid.Iterable Overloads for Collection Serialization
setContentFromScalarCollection(@Nonnull RequestAdapter, @Nonnull String, @Nonnull Iterable<T>)andsetContentFromParsable(@Nonnull RequestAdapter, @Nonnull String, @Nonnull Iterable<T>)overloads to natively support JavaCollectionandIterabletypes alongside arrays.Verification
./gradlew :components:abstractions:spotlessCheck— passed../gradlew :components:abstractions:spotbugsMain :components:abstractions:spotbugsTest— passed../gradlew :components:abstractions:test --rerun-tasks— 39 tests passed, 0 failures, 0 errors, 0 skipped.