From 85224f082e1860f3d50d169b517dfec0606a2cae Mon Sep 17 00:00:00 2001 From: KoalaTrapLord <265133236+KoalaTrapLord@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:57:46 -0400 Subject: [PATCH] fix: handle wrapped JSON object from /api/ml/models endpoint The API returns {"models":[...]} rather than a bare array. Added MlModelsResponse wrapper class and updated LoadModelHistory to unwrap the list before iterating, preventing the deserialization exception in TrainingController. --- .../Assets/Scripts/UI/TrainingController.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/unity-client/Assets/Scripts/UI/TrainingController.cs b/unity-client/Assets/Scripts/UI/TrainingController.cs index 7d9c2d7..9aa102c 100644 --- a/unity-client/Assets/Scripts/UI/TrainingController.cs +++ b/unity-client/Assets/Scripts/UI/TrainingController.cs @@ -108,7 +108,21 @@ namespace CommanderAILab.UI { try { - var models = JsonConvert.DeserializeObject>(json); + // The API returns a wrapped object {"models":[...]} rather than + // a bare array. Try the wrapped form first, then fall back to + // a bare array so either shape works without a backend change. + List models; + if (json.TrimStart().StartsWith("{")) + { + var wrapper = JsonConvert.DeserializeObject(json); + models = wrapper?.models ?? new List(); + } + else + { + models = JsonConvert.DeserializeObject>(json) + ?? new List(); + } + foreach (var m in models) { var row = Instantiate(historyRowPrefab, historyParent); @@ -298,6 +312,11 @@ namespace CommanderAILab.UI public string last_trained; } + [Serializable] private class MlModelsResponse + { + public List models; + } + [Serializable] private class MlModel { public string version;