{"record":{"id":"068d0681534a5e69","repo":"microsoft/aspire","slug":"expected-a-non-empty-kubernetes-microtime-value","errorCode":null,"errorMessage":"Expected a non-empty Kubernetes MicroTime value.","messagePattern":"Expected a non-empty Kubernetes MicroTime value\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/Model/KubernetesMicroTimeJsonConverter.cs","lineNumber":30,"sourceCode":"    private const string UtcFormat = \"yyyy-MM-dd'T'HH:mm:ss.ffffff'Z'\";\n    private const string OffsetFormat = \"yyyy-MM-dd'T'HH:mm:ss.ffffffzzz\";\n\n    public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType is JsonTokenType.Null)\n        {\n            return null;\n        }\n\n        if (reader.TokenType is not JsonTokenType.String)\n        {\n            throw new JsonException($\"Expected a string token for Kubernetes MicroTime but found {reader.TokenType}.\");\n        }\n\n        var value = reader.GetString();\n        if (string.IsNullOrEmpty(value))\n        {\n            throw new JsonException(\"Expected a non-empty Kubernetes MicroTime value.\");\n        }\n\n        return value.EndsWith('Z')\n            ? DateTime.ParseExact(value, UtcFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)\n            : DateTimeOffset.ParseExact(value, OffsetFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal).UtcDateTime;\n    }\n\n    public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)\n    {\n        if (value is null)\n        {\n            writer.WriteNullValue();\n            return;\n        }\n\n        // DCP models these fields as Kubernetes metav1.MicroTime, whose JSON shape is fixed-width:\n        //   \"2026-07-15T18:46:06.123000Z\"\n        // See https://github.com/kubernetes/apimachinery/blob/v0.36.0/pkg/apis/meta/v1/micro_time.go.","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/Model/KubernetesMicroTimeJsonConverter.cs#L12-L48","documentation":"Thrown by KubernetesMicroTimeJsonConverter.Read when the JSON value is a string but empty (or null-string). Kubernetes MicroTime values must be a non-empty RFC3339 timestamp; the converter rejects empty strings before attempting ParseExact.","triggerScenarios":"Deserializing JSON where a MicroTime field is \"\" (empty string). Note a literal JSON null is tolerated earlier and yields null, so this only fires for empty/whitespace strings.","commonSituations":"Server or mock omitting the timestamp but serializing an empty string instead of null; placeholder fixtures with blank timestamps; partially initialized DCP state.","solutions":["Emit null instead of \"\" when the timestamp is absent.","Populate the field with a valid RFC3339 UTC string such as \"2024-01-01T00:00:00Z\".","Sanitize incoming payloads: replace empty strings with null before deserialization if the source cannot be fixed."],"exampleFix":"// before\n{ \"lastUpdate\": \"\" }\n// after\n{ \"lastUpdate\": null }","handlingStrategy":"validation","validationCode":"if (payload.LastUpdate is \"\") payload.LastUpdate = null; // normalize empty to null before deserializing","typeGuard":"static bool IsValidMicroTime(string? s) => !string.IsNullOrEmpty(s) && DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out _);","tryCatchPattern":"try { time = JsonSerializer.Deserialize<KubernetesMicroTime>(ref reader, options); }\ncatch (JsonException ex) when (ex.Message.Contains(\"non-empty\")) { time = null; /* treat as missing */ }","preventionTips":["Serialize missing timestamps as null, never as \"\".","Use nullable types for optional timestamp fields in fixtures and mocks.","Validate fixture JSON against the Kubernetes MicroTime format."],"tags":["json","deserialization","kubernetes","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}