PHP code example of brettminnie / breakfast-serializer

1. Go to this page and download the library: Download brettminnie/breakfast-serializer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brettminnie / breakfast-serializer example snippets


   
    // To retrieve the json representation json of an object
    $jsonData = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()
        ->serialize($myClass);
   
   // To unserialize
   $myClass = BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer()
        ->deserialize($jsonData);
   
   //To serialize an object with a limited depth recursion (aka only some of it)
   $jsonData = 
      BDBStudios\BreakfastSerializer\SerializerFactory::getSerializer(
         BDBStudios\BreakfastSerializer\IsSerializable::FORMAT_JSON,
         2
      )
      ->serialize($myClass);