quicktype-core 23.3.18 → 23.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -350,7 +350,13 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
350
350
  if (converter !== undefined) {
351
351
  const typeSource = this.csType(targetType);
352
352
  this.emitLine("var converter = ", this.converterObject(converter), ";");
353
- this.emitLine("var ", variableName, " = (", typeSource, ")converter.ReadJson(reader, typeof(", typeSource, "), null, serializer);");
353
+ // The converter is for the non-null type, so if the target
354
+ // type is nullable we have to handle null ourselves.
355
+ const isNullable = targetType instanceof Type_1.UnionType &&
356
+ (0, TypeUtils_1.nullableFromUnion)(targetType) !== null;
357
+ this.emitLine("var ", variableName, " = ", isNullable
358
+ ? "reader.TokenType == JsonTokenType.Null ? null : "
359
+ : "", "(", typeSource, ")converter.Read(ref reader, typeof(", typeSource, "), options);");
354
360
  }
355
361
  else if (source.kind !== "null") {
356
362
  const output = targetType.kind === "double" ? targetType : source;
@@ -366,7 +372,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
366
372
  // FIXME: handle EOF
367
373
  this.emitLine("reader.Read();");
368
374
  this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
369
- this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
375
+ this.emitLine("while (reader.TokenType != JsonTokenType.EndArray)");
370
376
  this.emitBlock(() => {
371
377
  this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, (v) => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem", varGen);
372
378
  // FIXME: handle EOF
@@ -525,7 +531,24 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
525
531
  const converter = this.converterForType(xfer.sourceType);
526
532
  if (converter !== undefined) {
527
533
  this.emitLine("var converter = ", this.converterObject(converter), ";");
528
- this.emitLine("converter.WriteJson(writer, ", variable, ", serializer);");
534
+ // The converter is for the non-null type, so if the source
535
+ // type is nullable we have to handle null ourselves.
536
+ const maybeNullable = xfer.sourceType instanceof Type_1.UnionType
537
+ ? (0, TypeUtils_1.nullableFromUnion)(xfer.sourceType)
538
+ : null;
539
+ if (maybeNullable !== null) {
540
+ let member = variable;
541
+ if ((0, utils_1.isValueType)((0, Transformers_1.followTargetType)(maybeNullable))) {
542
+ member = [member, ".Value"];
543
+ }
544
+ this.emitLine("if (", variable, " == null)");
545
+ this.emitBlock(() => this.emitLine("writer.WriteNullValue();"));
546
+ this.emitLine("else");
547
+ this.emitBlock(() => this.emitLine("converter.Write(writer, ", member, ", options);"));
548
+ }
549
+ else {
550
+ this.emitLine("converter.Write(writer, ", variable, ", options);");
551
+ }
529
552
  }
530
553
  else {
531
554
  this.emitLine(this.serializeValueCode(variable), ";");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.18",
3
+ "version": "23.3.19",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",