schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.6k stars 199 forks source link

SchemaCrawler issues broken JSON when only one 'table' is eligible for printing #178

Closed ghost closed 6 years ago

ghost commented 6 years ago

Environment

Issue encountered with:

Issue reproduced with:

Issue

When SchemaCrawler outputs a JSON-encoded version of the schema which contains only one table, the JSON syntax is violated for any empty arrays and objects in the table object:

[
{
  "tables": {
    "foreignKeys": [][

    ],
    "indexes": [][

    ],
    "columns": [
      {
        "size": 10,
        "nullable": true,
        "databaseSpecificType": "int4",
        "generated": false,
        "dataType": "INTEGER",
        "name": "column_a",
        "width": "",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      },
      {
        "size": 10,
        "nullable": true,
        "databaseSpecificType": "int4",
        "generated": false,
        "dataType": "INTEGER",
        "name": "column_b",
        "width": "",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      },
      {
        "size": 10,
        "nullable": true,
        "databaseSpecificType": "int4",
        "generated": false,
        "dataType": "INTEGER",
        "name": "column_c",
        "width": "",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      }
    ],
    "name": "example_view",
    "fullName": "public.example_view",
    "type": "view",
    "triggers": [][

    ],
    "tableConstraints": [][

    ],
    "remarks": "",
    "primaryKey": {}
{}
  },
  "schemaCrawlerHeaderInfo": {
    "crawlTimestamp": "2018-04-18 10:10:04",
    "title": ""
  }
}]

Note the [] [] and the {} {}.

This does not occur when the schema contains more than one table, or when the schema contains no tables. I suspect that the issue lies in the JSON serialization code:

Because we consume the JSON programmatically, our current workaround is to select more than one view.

ghost commented 6 years ago

Oh, also note how the "tables" field now contains an object instead of an array.

sualeh commented 6 years ago

Please use the latest version of SchemaCrawler - v14.20.05