microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
32 stars 25 forks source link

Extra comma in serialized json output #1187

Closed mbursill closed 1 month ago

mbursill commented 1 month ago

When serializing an object that has a nested object, and setting the nested object to undefined, we're getting an extra comma in the serialized output:

const updateWidgetRequest: UpdateWidgetRequest = {
  name: 'Sproket',
  size: 5,
  inspectionDetails: undefined,
};

const jsonSerializationWriter = new JsonSerializationWriter();

jsonSerializationWriter.writeObjectValue(
  undefined,
  updateWidgetRequest,
  serializeUpdateWidgetRequest
);

const jsonBuffer = jsonSerializationWriter.getSerializedContent();
const decoder = new TextDecoder('utf-8');
const json = decoder.decode(jsonBuffer);

console.log(json);

The logged json will have:

{,"name":"Sproket","size":5}

The serializeUpdateWidgetRequest function is from the generated code.

baywet commented 1 month ago

Hi @mbursill Thanks for using kiota and for reaching out.

Can you make the following change:

-jsonSerializationWriter.writeObjectValue(
-  undefined,
-  updateWidgetRequest,
-  serializeUpdateWidgetRequest
-);
+serializeUpdateWidgetRequest(jsonSerializationWriter, updateWidgetRequest);

And see whether that solves your issue?

mbursill commented 1 month ago

The output in this case would be:

,"name":"Sproket","size":5,

It's worth noting that the issue happens when making an endpoint call that sends the root object. If I capture the traffic it looks like this:

image

The schema: swagger.json

It was tested on Kiota 1.13, 1.14 and the latest preview.

baywet commented 1 month ago

Thanks for the additional information. Are you generating with or without the backing store? Seems related to #1190

baywet commented 1 month ago

closing as duplicate of #1190