Skip to content

JsonSerialize error #106

@flier268

Description

@flier268

Describe the bug

There is a bug while post a IList<ViewModel> to server
Error message:

JsonTypeInfo metadata for type 'System.Collections.Generic.List`1[FPSII.Core.ApiClients.MachineStockLogModel]' was not provided by
  TypeInfoResolver of type 'FPSII.Core.ApiClients.SourceGenerationContext'. If using source generation, ensure that all root types passed to the
  serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.      於
  System.Text.Json.ThrowHelper.ThrowInvalidOperationException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
     於 System.Text.Json.JsonSerializer.Serialize(Object value, Type inputType, JsonSerializerContext context)

Steps to reproduce the bug

autosdk generate %TMP_JSON% ^
    --namespace FPSII.Core.ApiClients ^
    --clientClassName FPSIIApiClient ^
    --targetFramework net9.0 ^
    --output ../FPSII.Core/ApiClients

Expected behavior

No response

Screenshots

No response

NuGet package version

autosdk --version
0.28.1-dev.75+1be425961abbd87d5b3cf90b2564787a8872e78a

Additional context

AutoSDK generate this, this will cause error

            var __httpRequestContentBody = global::System.Text.Json.JsonSerializer.Serialize(request, request.GetType(), JsonSerializerContext);

Ai fix the issue with

            var __httpRequestContentBody = global::System.Text.Json.JsonSerializer.Serialize(request, (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::FPSII.Core.ApiClients.MachineStockLogModel>>)JsonSerializerContext.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::FPSII.Core.ApiClients.MachineStockLogModel>)));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions