09/03/2021

PHP Serialization

DateTime

// ✅ "O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}"
serialize(new DateTime('2020-01-01 00:00:00'));

// ✅
unserialize("O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}");




// ❌ {"date":"2020-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}
json_encode(new DateTime('2020-01-01 00:00:00'));

// ❌ array
json_decode('{"date":"2020-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}');




$adapter = $serializer->adapter(JsonTypeAdapter::class, DateTime::class);

// ✅ "2020-01-01T00:00:00.000+00:00"
$adapter->serialize(new DateTime('2020-01-01 00:00:00'));

// ✅ $value instanceof DateTime && $value == new DateTime('2020-01-01 00:00:00') 
$value = $adapter->deserialize('"2020-01-01T00:00:00.000+00:00"');

Any class

/**
 * @template T
 */
class ClassStub
{
	public function __construct(
		public int $primitive,
		public NestedStub $nested,
		#[SerializedName('date')] public mixed $generic,
	) {}
}

class NestedStub
{
	public string $field = 'something';
}



// ❌ {"primitive":1,"nested":{"field":"something"},"generic":{"date":"2020-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}}
json_encode(new ClassStub(1, new NestedStub(), new DateTime('2020-01-01 00:00:00')));

// ❌ array
json_decode('{"primitive":1,"nested":{"field":"something"},"generic":{"date":"2020-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}}');



// ✅ "O:85:"Tests\TenantCloud\Serialization\TypeAdapter\Primitive\ClassProperties\Stubs\ClassStub":3:{s:9:"primitive";i:1;s:6:"nested";O:86:"Tests\TenantCloud\Serialization\TypeAdapter\Primitive\ClassProperties\Stubs\NestedStub":1:{s:5:"field";s:9:"something";}s:7:"generic";O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}}"
serialize(new ClassStub(1, new NestedStub(), new DateTime('2020-01-01 00:00:00')));

// ✅ $value instanceof ClassStub && $value == new ClassStub(1, new NestedStub(), new DateTime('2020-01-01 00:00:00'))
$value = unserialize("O:85:"Tests\TenantCloud\Serialization\TypeAdapter\Primitive\ClassProperties\Stubs\ClassStub":3:{s:9:"primitive";i:1;s:6:"nested";O:86:"Tests\TenantCloud\Serialization\TypeAdapter\Primitive\ClassProperties\Stubs\NestedStub":1:{s:5:"field";s:9:"something";}s:7:"generic";O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}}");




$adapter = $serializer->adapter(
	JsonTypeAdapter::class, 
    new GenericObjectType(
    	ClassStub::class,
    	[new ObjectType(DateTime::class)]
    )
);

// ✅ {"primitive":1,"nested":{"field":"something"},"date":"2020-01-01T00:00:00.000+00:00"}
$adapter->serialize(new ClassStub(1, new NestedStub(), new DateTime('2020-01-01 00:00:00')));

// ✅ $value instanceof ClassStub && $value == new ClassStub(1, new NestedStub(), new DateTime('2020-01-01 00:00:00'))
$adapter->deserialize('{"primitive":1,"nested":{"field":"something"},"date":"2020-01-01T00:00:00.000+00:00"}');

Enums

class ValueEnumStub extends ValueEnum
{
	public static self $ONE;
	public static self $TWO;

	protected static function initializeInstances(): void
	{
		self::$ONE = new self('one');
		self::$TWO = new self('two');
	}
}




// ❌ Enum instances cannot be serialized because it cannot be deserialized.
serialize(ValueEnumStub::$ONE);

// ❌ Enum instances cannot be serialized because it cannot be deserialized.
ValueEnumStub::$ONE !== unserialize("serialized enum here");




// ✅ "\"one\""
json_encode(ValueEnumStub::$ONE);

// ❌ "one"
json_decode("\"one\"");



$adapter = $serializer->adapter(JsonTypeAdapter::class, DateTime::class);

// ✅ "one"
$adapter->serialize(ValueEnumStub::$ONE);

// ✅ $value === ValueEnumStub::$ONE
$value = $adapter->deserialize("one");

Models

class User extends Model {}




// ❌ "O:15:"App\Models\User":33:{s:13:"\x00*\x00connection";s:5:"mysql";s:8:"\x00*\x00table";s:5:"users";s:11:"\x00*\x00fillable";a:22:{i:0;s:4:"mode";i:1;s:9:"firstName";i:2;s:8:"lastName";i:3;s:7:"website";i:4;s:8:"address1";i:5;s:8:"address2";i:6;s:4:"city";i:7;s:5:"state";i:8;s:3:"zip";i:9;s:7:"country";i:10;s:3:"fax";i:11;s:7:"company";i:12;s:9:"isCompany";i:13;s:5:"phone";i:14;s:12:"office_phone";i:15;s:9:"time_zone";i:16;s:8:"currency";i:17;s:4:"lang";i:18;s:11:"measurement";i:19;s:11:"date_format";i:20;s:11:"time_format";i:21;s:9:"age_range";}s:8:"\x00*\x00casts";a:13:{s:2:"id";s:7:"integer";s:9:"isCompany";s:7:"boolean";s:11:"isConfirmed";s:7:"boolean";s:19:"is_domain_confirmed";s:7:"boolean";s:14:"dashboard_conf";s:5:"array";s:15:"email_scheduler";s:5:"array";s:6:"is_vip";s:7:"boolean";s:18:"is_daylight_saving";s:7:"boolean";s:24:"is_property_address_safe";s:7:"boolean";s:22:"has_active_on_boarding";s:7:"boolean";s:15:"is_deleting_now";s:7:"boolean";s:12:"has_password";s:7:"boolean";s:10:"deleted_at";s:8:"datetime";}s:13:"\x00*\x00attributes";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00appends";a:6:{i:0;s:4:"name";i:1;s:16:"has_old_password";i:2;s:11:"fullAddress";i:3;s:11:"cityAddress";i:4;s:21:"date_format_to_string";i:5;s:21:"time_format_to_string";}s:8:"\x00*\x00dates";a:4:{i:0;s:19:"remember_expires_at";i:1;s:13:"trial_ends_at";i:2;s:20:"subscription_ends_at";i:3;s:17:"delete_started_at";}s:10:"\x00*\x00virtual";a:1:{i:0;s:8:"date_utc";}s:9:"\x00*\x00hidden";a:6:{i:0;s:8:"password";i:1;s:12:"password_old";i:2;s:14:"remember_token";i:3;s:14:"dashboard_conf";i:4;s:8:"date_utc";i:5;s:10:"_view_date";}s:13:"\x00*\x00primaryKey";s:2:"id";s:10:"\x00*\x00keyType";s:3:"int";s:12:"incrementing";b:1;s:7:"\x00*\x00with";a:0:{}s:12:"\x00*\x00withCount";a:0:{}s:10:"\x00*\x00perPage";i:15;s:6:"exists";b:1;s:18:"wasRecentlyCreated";b:0;s:11:"\x00*\x00original";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00changes";a:0:{}s:17:"\x00*\x00classCastCache";a:0:{}s:13:"\x00*\x00dateFormat";N;s:19:"\x00*\x00dispatchesEvents";a:0:{}s:14:"\x00*\x00observables";a:0:{}s:12:"\x00*\x00relations";a:0:{}s:10:"\x00*\x00touches";a:0:{}s:10:"timestamps";b:1;s:10:"\x00*\x00visible";a:0:{}s:10:"\x00*\x00guarded";a:1:{i:0;s:1:"*";}s:36:"\x00*\x00refreshVirtualAttributesAfterSave";b:0;s:20:"\x00*\x00rememberTokenName";s:14:"remember_token";s:22:"\x00*\x00allowPromotionCodes";b:0;s:14:"\x00*\x00accessToken";N;s:16:"\x00*\x00forceDeleting";b:0;}"
serialize(User::first());

// ✅ $value == User::first()
$value = unserialize("O:15:"App\Models\User":33:{s:13:"\x00*\x00connection";s:5:"mysql";s:8:"\x00*\x00table";s:5:"users";s:11:"\x00*\x00fillable";a:22:{i:0;s:4:"mode";i:1;s:9:"firstName";i:2;s:8:"lastName";i:3;s:7:"website";i:4;s:8:"address1";i:5;s:8:"address2";i:6;s:4:"city";i:7;s:5:"state";i:8;s:3:"zip";i:9;s:7:"country";i:10;s:3:"fax";i:11;s:7:"company";i:12;s:9:"isCompany";i:13;s:5:"phone";i:14;s:12:"office_phone";i:15;s:9:"time_zone";i:16;s:8:"currency";i:17;s:4:"lang";i:18;s:11:"measurement";i:19;s:11:"date_format";i:20;s:11:"time_format";i:21;s:9:"age_range";}s:8:"\x00*\x00casts";a:13:{s:2:"id";s:7:"integer";s:9:"isCompany";s:7:"boolean";s:11:"isConfirmed";s:7:"boolean";s:19:"is_domain_confirmed";s:7:"boolean";s:14:"dashboard_conf";s:5:"array";s:15:"email_scheduler";s:5:"array";s:6:"is_vip";s:7:"boolean";s:18:"is_daylight_saving";s:7:"boolean";s:24:"is_property_address_safe";s:7:"boolean";s:22:"has_active_on_boarding";s:7:"boolean";s:15:"is_deleting_now";s:7:"boolean";s:12:"has_password";s:7:"boolean";s:10:"deleted_at";s:8:"datetime";}s:13:"\x00*\x00attributes";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00appends";a:6:{i:0;s:4:"name";i:1;s:16:"has_old_password";i:2;s:11:"fullAddress";i:3;s:11:"cityAddress";i:4;s:21:"date_format_to_string";i:5;s:21:"time_format_to_string";}s:8:"\x00*\x00dates";a:4:{i:0;s:19:"remember_expires_at";i:1;s:13:"trial_ends_at";i:2;s:20:"subscription_ends_at";i:3;s:17:"delete_started_at";}s:10:"\x00*\x00virtual";a:1:{i:0;s:8:"date_utc";}s:9:"\x00*\x00hidden";a:6:{i:0;s:8:"password";i:1;s:12:"password_old";i:2;s:14:"remember_token";i:3;s:14:"dashboard_conf";i:4;s:8:"date_utc";i:5;s:10:"_view_date";}s:13:"\x00*\x00primaryKey";s:2:"id";s:10:"\x00*\x00keyType";s:3:"int";s:12:"incrementing";b:1;s:7:"\x00*\x00with";a:0:{}s:12:"\x00*\x00withCount";a:0:{}s:10:"\x00*\x00perPage";i:15;s:6:"exists";b:1;s:18:"wasRecentlyCreated";b:0;s:11:"\x00*\x00original";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00changes";a:0:{}s:17:"\x00*\x00classCastCache";a:0:{}s:13:"\x00*\x00dateFormat";N;s:19:"\x00*\x00dispatchesEvents";a:0:{}s:14:"\x00*\x00observables";a:0:{}s:12:"\x00*\x00relations";a:0:{}s:10:"\x00*\x00touches";a:0:{}s:10:"timestamps";b:1;s:10:"\x00*\x00visible";a:0:{}s:10:"\x00*\x00guarded";a:1:{i:0;s:1:"*";}s:36:"\x00*\x00refreshVirtualAttributesAfterSave";b:0;s:20:"\x00*\x00rememberTokenName";s:14:"remember_token";s:22:"\x00*\x00allowPromotionCodes";b:0;s:14:"\x00*\x00accessToken";N;s:16:"\x00*\x00forceDeleting";b:0;}");




// ❌ "{"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}"
json_encode(User::first());

// ❌ array
json_decode('"{"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}"');



$adapter = $serializer->adapter(JsonTypeAdapter::class, User::class);

// ✅ 100008443
$adapter->serialize(User::first());

// ✅ $value == User::first()
$value = $adapter->deserialize(100008443);

Full models

class User extends Model {}




// ✅ "O:15:"App\Models\User":33:{s:13:"\x00*\x00connection";s:5:"mysql";s:8:"\x00*\x00table";s:5:"users";s:11:"\x00*\x00fillable";a:22:{i:0;s:4:"mode";i:1;s:9:"firstName";i:2;s:8:"lastName";i:3;s:7:"website";i:4;s:8:"address1";i:5;s:8:"address2";i:6;s:4:"city";i:7;s:5:"state";i:8;s:3:"zip";i:9;s:7:"country";i:10;s:3:"fax";i:11;s:7:"company";i:12;s:9:"isCompany";i:13;s:5:"phone";i:14;s:12:"office_phone";i:15;s:9:"time_zone";i:16;s:8:"currency";i:17;s:4:"lang";i:18;s:11:"measurement";i:19;s:11:"date_format";i:20;s:11:"time_format";i:21;s:9:"age_range";}s:8:"\x00*\x00casts";a:13:{s:2:"id";s:7:"integer";s:9:"isCompany";s:7:"boolean";s:11:"isConfirmed";s:7:"boolean";s:19:"is_domain_confirmed";s:7:"boolean";s:14:"dashboard_conf";s:5:"array";s:15:"email_scheduler";s:5:"array";s:6:"is_vip";s:7:"boolean";s:18:"is_daylight_saving";s:7:"boolean";s:24:"is_property_address_safe";s:7:"boolean";s:22:"has_active_on_boarding";s:7:"boolean";s:15:"is_deleting_now";s:7:"boolean";s:12:"has_password";s:7:"boolean";s:10:"deleted_at";s:8:"datetime";}s:13:"\x00*\x00attributes";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00appends";a:6:{i:0;s:4:"name";i:1;s:16:"has_old_password";i:2;s:11:"fullAddress";i:3;s:11:"cityAddress";i:4;s:21:"date_format_to_string";i:5;s:21:"time_format_to_string";}s:8:"\x00*\x00dates";a:4:{i:0;s:19:"remember_expires_at";i:1;s:13:"trial_ends_at";i:2;s:20:"subscription_ends_at";i:3;s:17:"delete_started_at";}s:10:"\x00*\x00virtual";a:1:{i:0;s:8:"date_utc";}s:9:"\x00*\x00hidden";a:6:{i:0;s:8:"password";i:1;s:12:"password_old";i:2;s:14:"remember_token";i:3;s:14:"dashboard_conf";i:4;s:8:"date_utc";i:5;s:10:"_view_date";}s:13:"\x00*\x00primaryKey";s:2:"id";s:10:"\x00*\x00keyType";s:3:"int";s:12:"incrementing";b:1;s:7:"\x00*\x00with";a:0:{}s:12:"\x00*\x00withCount";a:0:{}s:10:"\x00*\x00perPage";i:15;s:6:"exists";b:1;s:18:"wasRecentlyCreated";b:0;s:11:"\x00*\x00original";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00changes";a:0:{}s:17:"\x00*\x00classCastCache";a:0:{}s:13:"\x00*\x00dateFormat";N;s:19:"\x00*\x00dispatchesEvents";a:0:{}s:14:"\x00*\x00observables";a:0:{}s:12:"\x00*\x00relations";a:0:{}s:10:"\x00*\x00touches";a:0:{}s:10:"timestamps";b:1;s:10:"\x00*\x00visible";a:0:{}s:10:"\x00*\x00guarded";a:1:{i:0;s:1:"*";}s:36:"\x00*\x00refreshVirtualAttributesAfterSave";b:0;s:20:"\x00*\x00rememberTokenName";s:14:"remember_token";s:22:"\x00*\x00allowPromotionCodes";b:0;s:14:"\x00*\x00accessToken";N;s:16:"\x00*\x00forceDeleting";b:0;}"
serialize(User::first());

// ✅ $value == User::first()
$value = unserialize("O:15:"App\Models\User":33:{s:13:"\x00*\x00connection";s:5:"mysql";s:8:"\x00*\x00table";s:5:"users";s:11:"\x00*\x00fillable";a:22:{i:0;s:4:"mode";i:1;s:9:"firstName";i:2;s:8:"lastName";i:3;s:7:"website";i:4;s:8:"address1";i:5;s:8:"address2";i:6;s:4:"city";i:7;s:5:"state";i:8;s:3:"zip";i:9;s:7:"country";i:10;s:3:"fax";i:11;s:7:"company";i:12;s:9:"isCompany";i:13;s:5:"phone";i:14;s:12:"office_phone";i:15;s:9:"time_zone";i:16;s:8:"currency";i:17;s:4:"lang";i:18;s:11:"measurement";i:19;s:11:"date_format";i:20;s:11:"time_format";i:21;s:9:"age_range";}s:8:"\x00*\x00casts";a:13:{s:2:"id";s:7:"integer";s:9:"isCompany";s:7:"boolean";s:11:"isConfirmed";s:7:"boolean";s:19:"is_domain_confirmed";s:7:"boolean";s:14:"dashboard_conf";s:5:"array";s:15:"email_scheduler";s:5:"array";s:6:"is_vip";s:7:"boolean";s:18:"is_daylight_saving";s:7:"boolean";s:24:"is_property_address_safe";s:7:"boolean";s:22:"has_active_on_boarding";s:7:"boolean";s:15:"is_deleting_now";s:7:"boolean";s:12:"has_password";s:7:"boolean";s:10:"deleted_at";s:8:"datetime";}s:13:"\x00*\x00attributes";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00appends";a:6:{i:0;s:4:"name";i:1;s:16:"has_old_password";i:2;s:11:"fullAddress";i:3;s:11:"cityAddress";i:4;s:21:"date_format_to_string";i:5;s:21:"time_format_to_string";}s:8:"\x00*\x00dates";a:4:{i:0;s:19:"remember_expires_at";i:1;s:13:"trial_ends_at";i:2;s:20:"subscription_ends_at";i:3;s:17:"delete_started_at";}s:10:"\x00*\x00virtual";a:1:{i:0;s:8:"date_utc";}s:9:"\x00*\x00hidden";a:6:{i:0;s:8:"password";i:1;s:12:"password_old";i:2;s:14:"remember_token";i:3;s:14:"dashboard_conf";i:4;s:8:"date_utc";i:5;s:10:"_view_date";}s:13:"\x00*\x00primaryKey";s:2:"id";s:10:"\x00*\x00keyType";s:3:"int";s:12:"incrementing";b:1;s:7:"\x00*\x00with";a:0:{}s:12:"\x00*\x00withCount";a:0:{}s:10:"\x00*\x00perPage";i:15;s:6:"exists";b:1;s:18:"wasRecentlyCreated";b:0;s:11:"\x00*\x00original";a:58:{s:2:"id";i:100008442;s:9:"master_id";N;s:9:"subdomain";s:16:"bergstrom5281719";s:6:"domain";s:0:"";s:4:"role";s:2:"qa";s:4:"mode";N;s:8:"password";s:60:"$2y$04$0i3cLhsDfUBtUErjOSeZLuzSFmCwgeuos6hCK.YJI97qfZ9NAsfZ.";s:12:"password_old";s:0:"";s:14:"remember_token";N;s:9:"firstName";s:6:"Breana";s:8:"lastName";s:5:"Morar";s:5:"email";s:28:"2707279elenora39@hotmail.com";s:14:"previous_email";N;s:7:"website";N;s:8:"address1";s:18:"73015 Bettye Ville";s:8:"address2";s:8:"Apt. 759";s:4:"city";s:12:"Lake Tyshawn";s:5:"state";s:2:"MA";s:3:"zip";s:5:"69137";s:7:"country";s:2:"MT";s:9:"isCompany";i:0;s:7:"company";s:12:"Gislason LLC";s:3:"fax";s:20:"(589) 388-7946 x1769";s:5:"phone";s:12:"380995165880";s:12:"office_phone";N;s:9:"time_zone";s:15:"America/Chicago";s:8:"currency";N;s:4:"lang";N;s:11:"measurement";s:4:"feet";s:10:"_view_date";s:19:"2021-02-22 06:57:05";s:10:"visited_at";s:19:"2021-03-08 22:23:53";s:26:"notified_delete_account_at";N;s:14:"dashboard_conf";s:3118:"[{"x": 0, "y": 0, "id": 2, "drag": true, "name": "widget-quick-buttons", "show": true, "title": "Quick buttons", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 4, "y": 0, "id": 5, "drag": true, "name": "widget-units", "show": true, "title": "Vacant vs Occupied", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 5, "id": 6, "drag": true, "name": "widget-leases", "show": true, "title": "Lease Expiration", "width": 4, "height": 1, "filters": {"days": "30_days"}, "disabled": false}, {"x": 0, "y": 1, "id": 10, "drag": true, "name": "widget-listings", "show": true, "title": "Listings", "width": 8, "height": 1, "filters": {"on_website": 0}, "disabled": false}, {"x": 8, "y": 1, "id": 4, "drag": true, "name": "widget-common-payments-outstanding", "show": true, "title": "Outstanding / Last 30 days payments", "width": 4, "height": 1, "filters": {"days": "all_days"}, "disabled": false}, {"x": 0, "y": 2, "id": 8, "drag": true, "name": "widget-financials", "show": true, "title": "Financials", "width": 8, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 2, "id": 1, "drag": true, "name": "widget-to-do-list", "show": true, "title": "To do", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 3, "id": 7, "drag": true, "name": "widget-work-orders", "show": true, "title": "Maintenance", "width": 4, "height": 1, "filters": {"tab": 0}, "disabled": false}, {"x": 4, "y": 3, "id": 9, "drag": true, "name": "widget-rental-applications", "show": true, "title": "Rental Applications", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 3, "id": 3, "drag": true, "name": "widget-calendar", "show": true, "title": "Calendar", "width": 4, "height": 1, "filters": [], "disabled": true}, {"x": 0, "y": 4, "id": 11, "drag": true, "name": "widget-contacts", "show": true, "title": "Contacts", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 4, "id": 12, "drag": true, "name": "widget-messenger", "show": true, "title": "TC Messenger", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 6, "id": 13, "drag": true, "name": "widget-rentler-leads", "show": true, "title": "Rentler Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 4, "id": 14, "drag": true, "name": "widget-tips-tricks", "show": true, "title": "TenantCloud Tips&Tricks", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 0, "y": 7, "id": 17, "drag": true, "name": "widget-tcpayments", "show": false, "title": "TCPayments", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 4, "y": 5, "id": 18, "drag": true, "name": "widget-file-manager", "show": true, "title": "File Manager", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 5, "id": 19, "drag": true, "name": "widget-leads", "show": true, "title": "Leads", "width": 4, "height": 1, "filters": [], "disabled": false}, {"x": 8, "y": 0, "id": 20, "drag": false, "name": "widget-upgrade", "show": true, "title": "Upgrade", "width": 4, "height": 1, "filters": [], "disabled": true}]";s:15:"email_scheduler";N;s:11:"isConfirmed";i:1;s:12:"is_suspended";i:0;s:19:"is_domain_confirmed";i:0;s:22:"has_active_on_boarding";i:0;s:6:"reason";N;s:9:"stripe_id";N;s:10:"card_brand";N;s:14:"card_last_four";N;s:11:"date_format";i:2;s:11:"time_format";i:2;s:9:"age_range";N;s:12:"fraud_status";N;s:24:"is_property_address_safe";i:0;s:6:"is_vip";i:0;s:18:"is_daylight_saving";i:0;s:8:"date_utc";s:10:"2021-02-22";s:17:"delete_started_at";N;s:15:"is_deleting_now";i:0;s:12:"has_password";i:1;s:19:"remember_expires_at";N;s:12:"suspended_at";N;s:10:"created_at";s:19:"2021-02-22 06:02:27";s:10:"updated_at";s:19:"2021-03-05 14:09:37";s:10:"deleted_at";N;}s:10:"\x00*\x00changes";a:0:{}s:17:"\x00*\x00classCastCache";a:0:{}s:13:"\x00*\x00dateFormat";N;s:19:"\x00*\x00dispatchesEvents";a:0:{}s:14:"\x00*\x00observables";a:0:{}s:12:"\x00*\x00relations";a:0:{}s:10:"\x00*\x00touches";a:0:{}s:10:"timestamps";b:1;s:10:"\x00*\x00visible";a:0:{}s:10:"\x00*\x00guarded";a:1:{i:0;s:1:"*";}s:36:"\x00*\x00refreshVirtualAttributesAfterSave";b:0;s:20:"\x00*\x00rememberTokenName";s:14:"remember_token";s:22:"\x00*\x00allowPromotionCodes";b:0;s:14:"\x00*\x00accessToken";N;s:16:"\x00*\x00forceDeleting";b:0;}");




// ✅ "{"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}"
json_encode(User::first());

// ❌ array
json_decode('"{"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}"');



$adapter = $serializer->adapter(JsonTypeAdapter::class, User::class, [new WithoutDatabase('workorders')]);

// ✅ "{"workorders":[],"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}"
$adapter->serialize(User::first());

// ✅ if user in DB has not changed: $value == User::with('workorders')->first()
// ✅ if user in DB has changed: $value != User::with('workorders')->first()
$value = $adapter->deserialize('{"workorders":[],"id":100008443,"master_id":null,"subdomain":"torp4036128","domain":"","role":"developer","mode":null,"firstName":"Ernestine","lastName":"Lemke","email":"2930977joanny.monahan@gmail.com","previous_email":null,"website":null,"address1":"135 Efrain Falls","address2":"Apt. 891","city":"Laurenceberg","state":"LA","zip":"09369-0801","country":"ER","isCompany":false,"company":"Osinski-Mosciski","fax":"+1-805-533-7038","phone":"380995165880","office_phone":null,"time_zone":"America\/Chicago","currency":"USD","lang":null,"measurement":"meter","visited_at":"2021-02-25 12:16:34","notified_delete_account_at":null,"email_scheduler":null,"isConfirmed":true,"is_suspended":0,"is_domain_confirmed":false,"has_active_on_boarding":false,"reason":null,"stripe_id":null,"card_brand":null,"card_last_four":null,"date_format":2,"time_format":2,"age_range":null,"fraud_status":null,"is_property_address_safe":false,"is_vip":false,"is_daylight_saving":false,"delete_started_at":null,"is_deleting_now":false,"has_password":true,"remember_expires_at":null,"suspended_at":null,"created_at":"2021-02-19T01:23:07.000000Z","updated_at":"2021-02-16T16:38:18.000000Z","deleted_at":null,"name":"Ernestine Lemke","has_old_password":false,"fullAddress":"135 Efrain Falls, Laurenceberg, LA, 09369-0801, ER","cityAddress":"Laurenceberg, LA, 09369-0801, ER","date_format_to_string":"mm\/dd\/yyyy","time_format_to_string":"h:mm A"}');

Full picture - jobs

class SomeJob {
	public function __construct() {
		public User $first,
		#[WithoutDatabase()] 
		public User $second,
		public SomeEnum $enum,
	}
}




// ❌ Enum instances cannot be serialized because it cannot be deserialized
serialize(new SomeJob(User::first(), User::first(), SomeEnum::$ONE));

// ❌ Enum instances cannot be serialized because it cannot be deserialized
$value = unserialize("serialized job here");




// ❌ too long
json_encode(new SomeJob(User::first(), User::first(), SomeEnum::$ONE));

// ❌ array, enum as string
json_decode('serialized job here');



$adapter = $serializer->adapter(JsonTypeAdapter::class, SomeJob::class);

// ✅ "{"first":100008443,"second":{"id":100008444,"name":"Test", ..., "workorders": []},"enum":"one"}"
$adapter->serialize(new SomeJob(User::first(), User::first(), SomeEnum::$ONE));

// ✅ $value == new SomeJob(User::first(), User::first(), SomeEnum::$ONE)
$value = $adapter->deserialize('{"first":100008443,"second":{"id":100008444,"name":"Test", ..., "workorders": []},"enum":"one"}');

Magic type adapters

final class ValueEnumMapper
{
	/**
	 * @template TEnumValue
	 * @template TEnum of ValueEnum<TEnumValue>
	 *
	 * @param TEnum                            $value
	 * @param PrimitiveTypeAdapter<TEnumValue> $valueAdapter
	 *
	 * @return primitive
	 */
	#[MapTo]
	public function to(ValueEnum $value, PrimitiveTypeAdapter $valueAdapter): mixed
	{
		return $valueAdapter->serialize($value->value());
	}

	/**
	 * @template TEnumValue
	 * @template TEnum of ValueEnum<TEnumValue>
	 *
	 * @param primitive                        $value
	 * @param PrimitiveTypeAdapter<TEnumValue> $valueAdapter
	 *
	 * @return TEnum
	 */
	#[MapFrom]
	public function from(mixed $value, ObjectType $type, PrimitiveTypeAdapter $valueAdapter): ValueEnum
	{
		$enumClass = $type->getClassName();

		return $enumClass::fromValue($valueAdapter->deserialize($value));
	}
}

Magic type adapters

#[Immutable]
final class DateTimeMapper
{
	#[MapTo]
	public function to(DateTime $value): string
	{
		return $value->format(DateTimeInterface::RFC3339_EXTENDED);
	}

	#[MapFrom]
	public function from(string $value): DateTime
	{
		return new DateTime($value);
	}
}

Class properties naming

class NamingExample
{
	public function __construct(
		public int $camelCaseVariable = 1,
		#[SerializedName('customName')] public int $otherVariable = 1,
	) {}
}

$serializer = (new SerializerBuilder(null, null, BuiltInNamingStrategy::$SNAKE_CASE))
	->setCacheDir(__DIR__ . '/../../../tmp')
	->build();
            
// ✅ "{"camel_case_variable":1,"customName":1}"
$serializer->serialize(new NamingExample());

Discussion

PHP Serialization

By TenantCloud