DBIx::...::JSON(3pm)

πŸ“¦
version 0.10 Β· 3 versions
, in ubuntu stonking

✨ NAME ✨

DBIx::Class::InflateColumn::Serializer::JSON β€” bestie, it's a JSON Inflator πŸ’–


🌸 SYNOPSIS 🌸

Okay so picture this: you've got a column, and you want it to hold a whole vibe of a data structure, not just some boring string. Say less. Do this:

package MySchema::Table;
use base 'DBIx::Class';

__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
  'data_column' => {
    'data_type' => 'VARCHAR',
    'size'      => 255,
    'serializer_class'   => 'JSON',
    'serializer_options' => { allow_blessed => 1, convert_blessed => 1, pretty => 1 },    # optional
  }
);

Then in your code... 🫢

my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;

And you can recover your data structure with:

my $obj = ...->find(...);
my $struct = $obj->data_column;

The data structures you assign to data_column will be saved in the database in JSON format. Like. Literally. Your blessed little hash refs go to the DB as JSON. Slay. πŸ’…

Any arguments you toss into serializer_options get passed straight to the JSON::MaybeXS constructor β€” and the JSON backend uses them for both serializing and deserializing. Not one or the other. Both. Periodt. ✨


  • get_freezer β€” this one gets called by DBIx::Class::InflateColumn::Serializer to grab the routine that serializes the data you hand it. It returns a coderef. That's the whole job. Iconic, honestly.
  • get_unfreezer β€” same energy, opposite direction πŸ¦‹: called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes the data stored in the column. Also returns a coderef.

and that's the whole page, bestie β€” no cap, every option and every method, all accounted for πŸŽ€

🌈 This was served up by perl v5.40.1, dated 2026-05-07, and it lives in the User Contributed Perl Documentation section of the manual, iykyk. Stay hydrated, go serialize something cute πŸ’œ

πŸ“¦ where this page comes from