diff --git a/json-to-go.test.js b/json-to-go.test.js index df46018..a658068 100644 --- a/json-to-go.test.js +++ b/json-to-go.test.js @@ -159,6 +159,7 @@ function testFiles() { const testCases = [ "duplicate-top-level-structs", "double-nested-objects", + "array-with-mergable-objects", ]; for (const testCase of testCases) { diff --git a/tests/array-with-mergable-objects.go b/tests/array-with-mergable-objects.go new file mode 100644 index 0000000..0f575be --- /dev/null +++ b/tests/array-with-mergable-objects.go @@ -0,0 +1,15 @@ +type AutoGenerated struct { + Booleanfield bool `json:"booleanfield"` + Inconsistentarray []Inconsistentarray `json:"inconsistentarray,omitempty"` + Date string `json:"date,omitempty"` +} +type Features struct { + Age int `json:"age,omitempty"` + Height int `json:"height,omitempty"` + Gender string `json:"gender,omitempty"` +} +type Inconsistentarray struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Features Features `json:"features,omitempty"` +} diff --git a/tests/array-with-mergable-objects.json b/tests/array-with-mergable-objects.json new file mode 100644 index 0000000..3f1b980 --- /dev/null +++ b/tests/array-with-mergable-objects.json @@ -0,0 +1,28 @@ +{ + "booleanfield": true, + "inconsistentarray": [ + { + "id": 1, + "name": "John Doe", + "features": { + "age": 49, + "height": 175 + } + }, + { + "id": 2, + "name": "Jane Doe", + "features": { + "height": 164 + } + }, + { + "id": 3, + "name": "John Doe", + "features": { + "gender": "unknown" + } + } + ], + "date": "2024-07-22" +}