From e3fa3ca84b0e046ff7ca5ef678e04e73db3d1030 Mon Sep 17 00:00:00 2001 From: Victor Sergeyev Date: Thu, 23 Apr 2015 19:15:34 +0300 Subject: [PATCH] Add JsonPayloadSerializer serializer JsonPayloadSerializer exists in a several OpenStack projects such as cinder, ironic, magnum, nova, trove so there is a sense to keep it in oslo.messaging to avoid of code duplication. Change-Id: I77a6e5e3e717b0afcf17b6200d5b8ff5db6e3262 --- oslo_messaging/serializer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oslo_messaging/serializer.py b/oslo_messaging/serializer.py index 894f0f4a7..78bf983b6 100644 --- a/oslo_messaging/serializer.py +++ b/oslo_messaging/serializer.py @@ -12,12 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -__all__ = ['Serializer', 'NoOpSerializer'] +__all__ = ['Serializer', 'NoOpSerializer', 'JsonPayloadSerializer'] """Provides the definition of a message serialization handler""" import abc +from oslo_serialization import jsonutils import six @@ -74,3 +75,9 @@ class NoOpSerializer(Serializer): def deserialize_context(self, ctxt): return ctxt + + +class JsonPayloadSerializer(NoOpSerializer): + @staticmethod + def serialize_entity(context, entity): + return jsonutils.to_primitive(entity, convert_instances=True)