How to convert objects into array using serialization API? I'm trying to convert entity objects into array but it's not working. Can you please help me spotting the mistake. I need to use `serializer.normalizer.content_entity' service. The code I have written is:

class ComplexMergeResolver implements ConflictResolverInterface {

  protected $serializer;

  protected function setUp() {
    $this-&gt;serializer = $this-&gt;container-&gt;get('serializer.normalizer.content_entity');
  }

  /**
   * {@inheritdoc}
   */
  public function applies() {
   return TRUE;
  }

  /**
   * @param RevisionableInterface $revision1
   * @param RevisionableInterface $revision2
   * @param RevisionableInterface $revision3
   *
   * @return array
   */
  public function merge(RevisionableInterface $revision1, RevisionableInterface $revision2, RevisionableInterface $revision3) {
    $r1_array = $this-&gt;serializer-&gt;normalize($revision1, 'array');
    $r2_array = $this-&gt;serializer-&gt;normalize($revision2, 'array');
    $r3_array = $this-&gt;serializer-&gt;normalize($revision3, 'array');
    $merge = new ThreeWayMerge();
    $result = $merge-&gt;performMerge($r1_array, $r2_array, $r3_array);
    return $result;
  }
}


r1_array is returned empty, which means normalize method is not being called properly. Any help would do great. Thanks in advance.
I tried serializer.normalizer.content_entity but got no success in normalizing the (node) revision entity, or even node entity for that matter. It always resulted in the following error:


  PHP Fatal error:  Call to a member function normalize() on a non-object in core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php on line 28


For this I had to enable the serialization module. I also tried with the ContentEntityNormalizer provided by the "hal" module from core. Result same error:


  PHP Fatal error:  Call to a member function normalize() on a non-object in core/modules/hal/src/Normalizer/ContentEntityNormalizer.php on line 95


I had success with directly using the serializer service from the serialization module. The working code for serializing a node revision is given below. It was verified on /devel/php

$revision = node_revision_load(4);
$container = \Drupal::getContainer();
$normalizer = $container-&gt;get('serializer');
$normalized_array = $serializer-&gt;normalize($revision);
dsm($normalized_array);


Or combine line 2 and 3 above to get the serializer directly as 

$serializer = \Drupal::service('serializer');


In your setup() function, you need the following change:

$this-&gt;serializer = $this-&gt;container-&gt;get('serializer');


P.S: I am still trying to figure out why serializer.normalizer.content_entity is not working and throwing the errors.