Tenho a seguinte classe:
public class DeviceInfo
{
public string? ip { get; set; }
public string? deviceKey { get; set; }
public long time { get; set; }
public string? version { get; set; }
public int faceCount { get; set; }
public int personCount { get; set; }
}
Por outro lado, tenho esta string json:
{
"ip": "192.168.0.146",
"deviceKey": "A34CC830D348437A",
"time": "1741375392869",
"version": "1.41.9.7",
"faceCount": "0",
"personCount": "0"
}
Ao executar:
JsonSerializerOptions? options = customImplementation ? new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers = { JsonImplementationAttribute.ReadAttributeFromTypeInfo }
}
} : null;
JsonSerializer.Deserialize<DeviceInfo>(json, options);
Recebi este erro:
Exceção: System.Text.Json.JsonException: O valor JSON não pôde ser convertido para System.Int64. Caminho: $.time | LineNumber: 0 | BytePositionInLine: 75. ---> System.InvalidOperationException: Não é possível obter o valor de um tipo de token 'String' como um número. em System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType) em System.Text.Json.Utf8JsonReader.TryGetInt64(Int64& value) em System.Text.Json.Utf8JsonReader.GetInt64() em System.Text.Json.Serialization.Metadata.JsonPropertyInfo
1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter
1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) em System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue) at System.Text.Json.Serialization.JsonConverter
1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- Fim do rastreamento de pilha de exceção interna --- em System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& estado, Utf8JsonReader& leitor, Exception ex) em System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan
1 utf8Json, JsonTypeInfo1 jsonTypeInfo, Nullable
1 actualByteCount)
em System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 json, JsonTypeInfo
1 jsonTypeInfo) em System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions opções) em Modules.Integration.Extensions.JsonExtensions.ToObject[T](Objeto o, Boolean customImplementation) em C:\WorkingFolder\Projetos\Desytec\Desenvolvimento\Desytec-Security-Platform\Web\Módulos\Módulos.Integração\Extensões\JsonExtensions.cs:linha 29 em AdmsServer.Services.PassDeviceService.SaveOptions(String serialNumber) em C:\WorkingFolder\Projetos\Desytec\Desenvolvimento\Desytec-Security-Platform\Web\Dispositivos\AdmsServer\Serviços\PassDeviceService.cs:linha 237 em AdmsServer.Controllers.Drivers.API.PassController.Heartbeat(dispositivo DeviceInfo) em C:\WorkingFolder\Projetos\Desytec\Desenvolvimento\Desytec-Security-Platform\Web\Dispositivos\AdmsServer\Controladores\Drivers\API\PassController.cs:linha 83
O que há de errado aqui?
Cumprimentos