diff --git a/lib/datatypes/other.js b/lib/datatypes/other.js index b4b277a..1b38681 100644 --- a/lib/datatypes/other.js +++ b/lib/datatypes/other.js @@ -7,21 +7,24 @@ exports.get = function(resultSet, idx) { var obj = resultSet.getObject(idx); - // Postgres special types not covered by JDBC - if (obj instanceof Packages.org.postgresql.util.PGobject) { - var type = obj.getType(); - switch (type) { - case "json": - case "jsonb": - obj = JSON.parse(obj.toString()); - break; - default: - throw new Error("Unsupported data type: " + type); + if (obj !== null) { + // Postgres special types not covered by JDBC + if (obj instanceof Packages.org.postgresql.util.PGobject) { + var type = obj.getType(); + switch (type) { + case "json": + case "jsonb": + obj = JSON.parse(obj.toString()); + break; + default: + throw new Error("Unsupported data type: " + type); + } + return obj; + } else { + throw new Error("Unsupported object data type: " + obj.toString()); } - return obj; - } else { - throw new Error("Unsupported object data type: " + obj.toString()); } + return obj; }; /** diff --git a/test/postgresql/datatype_json_test.js b/test/postgresql/datatype_json_test.js index c422cd8..f294593 100644 --- a/test/postgresql/datatype_json_test.js +++ b/test/postgresql/datatype_json_test.js @@ -24,7 +24,6 @@ var store, Event, EventB; exports.setUp = function() { store = new Store(Store.initConnectionPool(config.postgresql)); - store.setEntityCache(new Cache()); Event = store.defineEntity("Event", MAPPING_EVENT_JSON); EventB = store.defineEntity("EventB", MAPPING_EVENT_JSONB); store.syncTables(); @@ -56,6 +55,19 @@ exports.testSaveObject = function() { assert.strictEqual(EventB.all().length, 1); }; +exports.testGetSetNull = function() { + var values = [null, undefined]; + for each (let value in values) { + let event = new Event({ + "slog": "some event", + "data": value + }); + event.save(); + assert.isNotNull(Event.get(event.id, true)); + assert.isNull(Event.get(event.id, true).data); + } +}; + exports.testQueryObjects = function() { // populate the tables store.beginTransaction();