Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vKgVf-004j4z-0h for psycopg@arkaria.postgresql.org; Sun, 16 Nov 2025 17:25:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vKgVb-00B2gg-32 for psycopg@arkaria.postgresql.org; Sun, 16 Nov 2025 17:25:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vKgVb-00B2gY-0L for psycopg@lists.postgresql.org; Sun, 16 Nov 2025 17:25:51 +0000 Received: from fout-b6-smtp.messagingengine.com ([202.12.124.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vKgVW-0084C6-2Q for psycopg@lists.postgresql.org; Sun, 16 Nov 2025 17:25:50 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id BE6DB1D00184; Sun, 16 Nov 2025 12:25:43 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sun, 16 Nov 2025 12:25:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1763313943; x=1763400343; bh=D6h5xTBGHPfxApb8a9AWMBREzN4Cm/Yk5VqHWE1PLQE=; b= benF5TRr6+JcNIE5ZdxPNYdv9oJbN3UiIRc2rgJe5ld3Dr/XwbfdT5VSHIDZaWS6 WhWHhYm/mgQgXjwSqs/jOFB3qgJHY8NQb+bBZ2WL8Ky2MMrsG5q2yQa3pluCRcYY VQtUcUcrjG+wj/hE980ySWO/FJUB8f8Hc21ckijdb0Qu645J14ELmqcT+VM05FHk criMfldIjFVnWlQEKSfej9mrAal/5MSy5LEiJ5JVx0Lzvu4VpSlL9WJudWjKbxFL fyos0NjEm+WXHZykOGQOdFAwwprIGVfUuoBm2fiDw6H1oIosLlkSw6n9i7XSXxLG k8Gr0ZQ/hg0Z595NpbPXMw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1763313943; x=1763400343; bh=D 6h5xTBGHPfxApb8a9AWMBREzN4Cm/Yk5VqHWE1PLQE=; b=jJbbseeDhVNjtWTvZ jgebzwHYxWug9MfESayburx+arsTIZy9Y3BdZT2nlpAgd4MZUO0k5KPBIEreN3QE /elx0ulXNd0EkSgpkmEEIRTc2nURkxgkq4DQjo94CTUigJyxQ9dbQvZepy4fv0LG gc3EJ5sl3lHxXS1x02WvqxWeJfusKuCx8d1Vc0JIldePRoJ74ZChFnWz3DZuFfjK wHAakEjOY/Pogk8MMDdxOo3MlwFjV09xjD+RJvDMf8dqbtlgE0pkAsmAj3JMx13t EQ6Cn3W34zoPGtwRxM68iENuWfD21fxql3TVUh/2glm+hiU2a1PF6My/OVYHU7A1 1GvhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvudeiudekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertd dtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleetgeffhefhtd evleeklefftdfgjeelieetudfhhefhteetteetteelgfdtvefhnecuffhomhgrihhnpehp shihtghophhgrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgs pghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepgihofhesth hhvggsuhhilhgurdgtohhmpdhrtghpthhtohepphhshigtohhpgheslhhishhtshdrphho shhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Nov 2025 12:25:42 -0500 (EST) Message-ID: Date: Sun, 16 Nov 2025 09:25:42 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Overriding default adapters in psycopg To: Christophe Pettus , psycopg@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/16/25 08:56, Christophe Pettus wrote: > Hi! > > I am attempting to override the default adapters for JSON and JSONB in psycopg (3), but I am not quite sure how to go about it (I'm testing using orjson for serialization and deserialization). This doesn't appear to work: > >> class CyanJSONBLoader(Loader): >> def load(self, data): >> return orjson.loads(data) >> >> psycopg.adapters.register_loader("jsonb", CyanJSONBLoader) >> >> class CyanJSONBDumper(Dumper): >> def dump(self, obj): >> return orjson.dumps(obj) >> >> psycopg.adapters.register_dumper("jsonb", CyanJSONBDumper) >> > > The calls work, but the dump/load functions are never called. I think you might need to use: https://www.psycopg.org/psycopg3/docs/basic/adapt.html#adapt-json > > Thanks! > -- Adrian Klaver adrian.klaver@aklaver.com