From b85639f3577f5d7dc638485dfdadbdda7cd1e680 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Mon, 28 Jul 2025 14:41:29 +0200 Subject: [PATCH 1/2] fix: only read 'properties' if present --- .../v1/api/collections/CollectionConfig.java | 17 ++++++++++------- .../client6/v1/internal/json/JSONTest.java | 12 +++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java index 8381623be..c1833f720 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java @@ -264,16 +264,19 @@ public void write(JsonWriter out, CollectionConfig value) throws IOException { public CollectionConfig read(JsonReader in) throws IOException { var jsonObject = JsonParser.parseReader(in).getAsJsonObject(); - var mixedProperties = jsonObject.get("properties").getAsJsonArray(); var references = new JsonArray(); var properties = new JsonArray(); - for (var property : mixedProperties) { - var dataTypes = property.getAsJsonObject().get("dataType").getAsJsonArray(); - if (dataTypes.size() == 1 && DataType.KNOWN_TYPES.contains(dataTypes.get(0).getAsString())) { - properties.add(property); - } else { - references.add(property); + if (jsonObject.has("properties") && jsonObject.get("properties").isJsonArray()) { + var mixedProperties = jsonObject.get("properties").getAsJsonArray(); + + for (var property : mixedProperties) { + var dataTypes = property.getAsJsonObject().get("dataType").getAsJsonArray(); + if (dataTypes.size() == 1 && DataType.KNOWN_TYPES.contains(dataTypes.get(0).getAsString())) { + properties.add(property); + } else { + references.add(property); + } } } diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index 82a205ae9..0e678e08c 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -400,7 +400,7 @@ public void test_ReferenceAddManyResponse_CustomDeserializer() { "result": { "status": "SUCCESS", "errors": {} } }, { - "result": { "status": "FAILED", "errors": { + "result": { "status": "FAILED", "errors": jsonObject.has("properties") && { "error": [ "oops" ] }} } @@ -413,4 +413,14 @@ public void test_ReferenceAddManyResponse_CustomDeserializer() { .as("response contains 1 error") .hasSize(1); } + + @Test + public void test_CollectionConfig_read_empty() { + var json = """ + { "class": "BarebonesCollection" } + """; + Assertions.assertThatCode(() -> JSON.deserialize(json, CollectionConfig.class)) + .as("deserialize CollectionConfig with no properties") + .doesNotThrowAnyException(); + } } From a93b9d7745d417d498ae0863154fcaace8927632 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Mon, 28 Jul 2025 14:47:56 +0200 Subject: [PATCH 2/2] chore: add more defensive checks for moduleConfig --- .../weaviate/client6/v1/api/collections/CollectionConfig.java | 2 +- .../java/io/weaviate/client6/v1/internal/json/JSONTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java index c1833f720..70448ce6a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java @@ -289,7 +289,7 @@ public CollectionConfig read(JsonReader in) throws IOException { // Separate modules into reranker- and generative- modules. var rerankerModules = new JsonArray(); - if (jsonObject.has("moduleConfig")) { + if (jsonObject.has("moduleConfig") && jsonObject.get("moduleConfig").isJsonObject()) { var moduleConfig = jsonObject.remove("moduleConfig").getAsJsonObject(); moduleConfig.entrySet().stream() diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index 0e678e08c..7763710a2 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -400,7 +400,7 @@ public void test_ReferenceAddManyResponse_CustomDeserializer() { "result": { "status": "SUCCESS", "errors": {} } }, { - "result": { "status": "FAILED", "errors": jsonObject.has("properties") && { + "result": { "status": "FAILED", "errors": { "error": [ "oops" ] }} }