Serialize extref to JSON

@param JsonDeserializationVisitor $visitor Visitor
@param string                     $url     Extref URL
@param array                      $type    Type
@param Context                    $context Context
@return ExtReference|null
962044
public function deserializeExtReferenceFromJson(
        JsonDeserializationVisitor $visitor,
        $url,
        array $type,
        Context $context
    ) {
        try {
            return $this->converter->getExtReference(
                $visitor->visitString($url, $type, $context)
            );
        } catch (\InvalidArgumentException $e) {
            return null;
        }
    }
1226389
public final <T> SerializerJson<T> serializer(Type type)
  {
    SerializerJson<T> ser = (SerializerJson<T>) _serTypeMap.get(type);
    
    if (ser == null) {
      TypeRef typeRef = TypeRef.of(type);
      Class<T> rawClass = (Class<T>) typeRef.rawClass();
      
      ser = serializer(rawClass).withType(typeRef, this);
      
      _serTypeMap.putIfAbsent(type, ser);
      
      ser = (SerializerJson<T>) _serTypeMap.get(type);
    }
    
    return ser;
  }
423096
public function serializeToXml(XmlSerializationVisitor $visitor, $entity, array $type, Context $context)
    {
        $visitor->getCurrentNode()->appendChild(
            $formNode = $visitor->getDocument()->createElement('id', $type['params']['id'])
        );

        return $formNode;
    }
611484
public function serializeSchemaEnumToJson(
        JsonSerializationVisitor $visitor,
        SchemaEnum $schemaEnum,
        array $type,
        Context $context
    ) {
        return $schemaEnum->getValues();
    }
147190
protected function serialize($obj, $type = 'json')
    {
        $context = new SerializationContext();
        $context->setSerializeNull($this->isSerializeNull());

        $builder = SerializerBuilder::create();
        $builder
            ->configureListeners(function (EventDispatcher $dispatcher) {
                $dispatcher->addListener('serializer.pre_serialize',
                    function (PreSerializeEvent $event) {
                        if ($event->getObject() instanceof EntityCollection) {
                            $event->setType('EntityCollection');
                        }
                    }
                );
            })
            ->configureHandlers(function (HandlerRegistry $registry) {
                $collectionHandler = function (JsonSerializationVisitor $visitor, $obj, array $type, Context $context) {
                    $nav = $visitor->getNavigator();
                    if (count($obj->getCollection()) < 1) {
                        return true;
                    }

                    return $nav->accept($obj->getCollection(), ['name' => 'array'], $context);
                };

                // Entity Array Handler
                $registry->registerHandler(
                    'serialization',
                    'EntityCollection',
                    'json',
                    $collectionHandler);

                // DateTime Handler ISO 8601 date "yyyy-mm-dd'T'HH:mm:ssZ"
                $registry->registerHandler('serialization', 'DateTime', 'json',
                    function ($visitor, \DateTime $obj, array $type, Context $context) {
                        return $obj->format('c');
                    }
                );
            });

        $serializer = $builder->build();

        return $serializer->serialize($obj, $type, $context);
    }
44943
public function onExistingVisit(Request $request, Visitor $visitor, $action)
    {
        $idAction = $visitor->getVisitorColumn('visit_entry_idaction_url');

        if (is_null($idAction) && !empty($action)) {
            $idAction = $action->getIdActionUrlForEntryAndExitIds();
            if (!empty($idAction)) {
                return $idAction;
            }
        }

        return false;
    }
574028
public function deserialize(VisitorInterface $visitor, $data, Type $type, Context $context): ?UuidInterface
    {
        if (empty($data)) {
            return $visitor->visitNull(null, Type::null(), $context);
        }

        return Uuid::fromString($data);
    }
713819
public function doSerialize(
        JsonSerializationVisitor $visitor,
        ExtensionContainer $container,
        array $type,
        Context $context
    ) {
        return $context->accept($container->toArray());
    }
27741
public function serializeHashToJson(
        JsonSerializationVisitor $visitor,
        Hash $data,
        array $type,
        Context $context
    ) {
        return new Hash($data);
    }
19669
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('VersionList');
        $visitor->setHeader('Content-Type', $generator->getMediaType('VersionList'));
        //@todo Needs refactoring, disabling certain headers should not be done this way
        $visitor->setHeader('Accept-Patch', false);

        $generator->startAttribute('href', $data->path);
        $generator->endAttribute('href');

        $generator->startList('VersionItem');
        foreach ($data->versions as $version) {
            $generator->startHashElement('VersionItem');

            $generator->startObjectElement('Version');
            $generator->startAttribute(
                'href',
                $this->router->generate(
                    'ezpublish_rest_loadContentInVersion',
                    array(
                        'contentId' => $version->getContentInfo()->id,
                        'versionNumber' => $version->versionNo,
                    )
                )
            );
            $generator->endAttribute('href');
            $generator->endObjectElement('Version');

            $visitor->visitValueObject($version);

            $generator->endHashElement('VersionItem');
        }
        $generator->endList('VersionItem');

        $generator->endObjectElement('VersionList');
    }
120852
public static <T> T readUrlAsObject(String url, Class<T> type) {
		String contents = getUrlContents(url);
		ObjectMapper mapper = new ObjectMapper();
		mapper.enableDefaultTyping();

		try {
			return mapper.readValue(contents, type);
		} catch (IOException e) {
			JK.throww(e);
			return null;
		}
	}
617139
public static void visit(Object instance, TypeToken<?> inspectType, Visitor firstVisitor, Visitor... moreVisitors) {

    try {
      List<Visitor> visitors = ImmutableList.<Visitor>builder().add(firstVisitor).add(moreVisitors).build();

      for (TypeToken<?> type : inspectType.getTypes().classes()) {
        if (Object.class.equals(type.getRawType())) {
          break;
        }

        for (Field field : type.getRawType().getDeclaredFields()) {
          if (!field.isAccessible()) {
            field.setAccessible(true);
          }
          for (Visitor visitor : visitors) {
            visitor.visit(instance, inspectType, type, field);
          }
        }

        for (Method method : type.getRawType().getDeclaredMethods()) {
          if (!method.isAccessible()) {
            method.setAccessible(true);
          }
          for (Visitor visitor : visitors) {
            visitor.visit(instance, inspectType, type, method);
          }
        }
      }
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
1259734
public function serializeDateTime(VisitorInterface $visitor, \DateTime $date, array $type, Context $context)
    {
        return $visitor->visitString($this->dateConverter->formatDateTime($date), $type, $context);
    }
1022379
public function serializeContextFunction($context)
    {
        $json = array();

        foreach ($context as $key => $value) {
            if (!in_array($key, array('_parent', 'assetic', 'app')) && !preg_match('#sonata#', $key)) {
                try {
                    $serializedValue = $this->serializer->serialize($value, 'json');
                } catch (\JMS\Serializer\Exception\RuntimeException $ex) {
                    $serializedValue = json_encode($value, null, 2);
                }

                if (!empty($serializedValue)) {
                    $json[] = $this->serializer->serialize($key, 'json').':'.$serializedValue;
                }
            }
        }

        return '{'.implode(',', $json).'}';
    }
1038944
public function serializeImageToJson(JsonSerializationVisitor $visitor, Image $image, array $type, Context $context)
    {
        $type['name'] = 'array';

        return $visitor->visitArray([
            'id' => $image->getId(),
            'url' => $this->imageManager->filePathToWebPath($image->getPath())
        ], $type, $context);
    }
123946
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $restFieldDefinition = $data->fieldDefinition;

        parent::visit($visitor, $generator, $restFieldDefinition);

        $draftUriPart = $this->getUrlTypeSuffix($restFieldDefinition->contentType->status);
        $visitor->setHeader(
            'Location',
            $this->router->generate(
                "ezpublish_rest_loadContentType{$draftUriPart}FieldDefinition",
                array(
                    'contentTypeId' => $restFieldDefinition->contentType->id,
                    'fieldDefinitionId' => $restFieldDefinition->fieldDefinition->id,
                )
            )
        );
        $visitor->setStatus(201);
    }
459164
public function serializeEBDateTime(VisitorInterface $visitor, \DateTime $date, array $type, Context $context)
    {
        return ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData)
            ? $visitor->visitSimpleString($date->format($this->getFormat($type)), $type, $context)
            : $visitor->visitString($date->format($this->getFormat($type)), $type, $context);
    }