diff --git a/src/dialects/mariadb/query.js b/src/dialects/mariadb/query.js index 0e557e299f95..a2f823e2bbc9 100644 --- a/src/dialects/mariadb/query.js +++ b/src/dialects/mariadb/query.js @@ -188,7 +188,9 @@ export class MariaDbQuery extends AbstractQuery { if (modelField.type instanceof DataTypes.JSON) { // Value is returned as String, not JSON rows = rows.map(row => { - if (row[modelField.fieldName] && typeof row[modelField.fieldName] === 'string') { + // JSON fields for MariaDB server 10.5.2+ already results in JSON format, skip JSON.parse + // this is due to this https://jira.mariadb.org/browse/MDEV-17832 and how mysql2 connector interacts with MariaDB and JSON fields + if (row[modelField.fieldName] && typeof row[modelField.fieldName] === 'string' && !this.connection.info.hasMinVersion(10, 5, 2)) { row[modelField.fieldName] = JSON.parse(row[modelField.fieldName]); } diff --git a/test/integration/json.test.js b/test/integration/json.test.js index 58ef71be4615..3dc53f7416dd 100644 --- a/test/integration/json.test.js +++ b/test/integration/json.test.js @@ -200,6 +200,12 @@ describe('model', () => { expect(user.username).to.equal('anna'); }); + it('should be able to store strings', async function () { + await this.User.create({ username: 'swen', emergency_contact: 'joe' }); + const user = await this.User.findOne({ where: { username: 'swen' } }); + expect(user.emergency_contact).to.equal('joe'); + }); + it('should be able to store values that require JSON escaping', async function () { const text = 'Multi-line \'$string\' needing "escaping" for $$ and $1 type values';