diff --git a/packages/core/src/hydration/ObjectHydrator.ts b/packages/core/src/hydration/ObjectHydrator.ts index 1b1f76387479..d1149eb6db32 100644 --- a/packages/core/src/hydration/ObjectHydrator.ts +++ b/packages/core/src/hydration/ObjectHydrator.ts @@ -96,14 +96,7 @@ export class ObjectHydrator extends Hydrator { ` if (${preCond}typeof data${dataKey} !== 'undefined') {`, ` if (convertCustomTypes) {`, ` const value = convertToJSValue_${convertorKey}(data${dataKey});`, - ); - - // make sure the value is comparable, but skip this for JSON props as it can result in double encoding - if (!(prop.customType instanceof JsonType)) { - ret.push(` data${dataKey} = convertToDatabaseValue_${convertorKey}(value);`); - } - - ret.push( + ` data${dataKey} = convertToDatabaseValue_${convertorKey}(value);`, // make sure the value is comparable ` entity${entityKey} = value;`, ` } else {`, ` entity${entityKey} = data${dataKey};`, diff --git a/tests/issues/GH4078.test.ts b/tests/issues/GH4078.test.ts new file mode 100644 index 000000000000..7d3b61b33e16 --- /dev/null +++ b/tests/issues/GH4078.test.ts @@ -0,0 +1,54 @@ +import { Entity, JsonType, PrimaryKey, Property } from '@mikro-orm/core'; +import { MikroORM } from '@mikro-orm/mysql'; +import { mockLogger } from '../helpers'; + +type Setup = { + limits?: boolean; + fallbackFees?: boolean; +}; + +@Entity() +class Contract { + + @PrimaryKey() + id!: number; + + @Property() + title!: string; + + @Property({ type: JsonType, nullable: true }) + setup: Setup | null = null; + +} + +let orm: MikroORM; + +beforeAll(async () => { + orm = await MikroORM.init({ + entities: [Contract], + dbName: `mikro_orm_test_4078`, + port: 3308, + }); + + await orm.schema.refreshDatabase(); +}); + +afterAll(async () => { + await orm.close(true); +}); + +test('4078', async () => { + await orm.em.insert(Contract, { + id: 1, + title: 't', + setup: { + limits: true, + fallbackFees: false, + }, + }); + orm.em.clear(); + await orm.em.findOneOrFail(Contract, 1); + const mock = mockLogger(orm); + await orm.em.flush(); + expect(mock).not.toBeCalled(); +});