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
This commit is contained in:
Victor Sergeyev 2015-04-23 19:15:34 +03:00
parent 9dd84417fb
commit e3fa3ca84b
1 changed files with 8 additions and 1 deletions

View File

@ -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)