Skip to content

Gracefully skip serialization of properties backed by non-serializable objects #54

@bradjones1

Description

@bradjones1

I am using this library to serialize value objects provided by commerceguys/addressing, that is, a library I do not maintain in-tree.

One of the properties of the object I am serializing is defined as

/**
 * Gets the subdivision children.
 *
 * @return ArrayCollection|LazySubdivisionCollection The subdivision children.
 */
public function getChildren(): Collection
{
    return $this->children;
}

None of these classes has the kind of typed return values object-hydrator is looking for, so it fails with Unable to serialize object on the parent object being serialized. It would be nice if the library could gracefully skip properties which are not serializable for whatever reason. I understand that in many cases failing early would be preferable (that is, when writing your own code that needs to be symmetrically serializable. But in other cases, such as using this library to predictably serialize value objects of various types, we can be a little more liberal.

If I owned the code in question then I could annotate the properties to be skipped. But since this is out-of-tree, I need to be able to handle this condition from outside. I'm going to experiment with a customized service(s) to DefinitionProvider to do something like this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions