JMSSerializerBundle: NotAcceptableException when serializing null

When serialize_null: false:

jms_serializer:
    default_context:
        serialization:
            serialize_null: false

And one tries to serialize null, JMS version 3.0 started throwing:

JMS\Serializer\Exception\NotAcceptableException:

  at vendor/jms/serializer/src/GraphNavigator/SerializationGraphNavigator.php:136
  at JMS\Serializer\GraphNavigator\SerializationGraphNavigator->accept(null, array('name' => 'NULL', 'params' => array()))
     (vendor/jms/serializer/src/Serializer.php:249)
  at JMS\Serializer\Serializer->visit(object(SerializationGraphNavigator), object(JsonSerializationVisitor), object(SerializationContext), null, 'json', null)
     (vendor/jms/serializer/src/Serializer.php:162)
  at JMS\Serializer\Serializer->serialize(null, 'json', object(SerializationContext))

This was not the case in the older versions.

Is there a way to prevent this error, but still be able to prevent serializing null values at a deeper levels of json structures? Which means keep serialize_null: false so resulting json does not contain nulls.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

i guess so… but tests should uncover eventual bugs

Since the issue is not solved and https://github.com/schmittjoh/JMSSerializerBundle/issues/788#issuecomment-598189892 just proposes a solution, i’m re opening the ticket