

from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six


class Json(fields.FieldType):
    def coerce(self, obj, attr, value):
        if isinstance(value, six.string_types):
            loaded = json.loads(value)
            return loaded
        return value

    def from_primitive(self, obj, attr, value):
        return self.coerce(obj, attr, value)

    def to_primitive(self, obj, attr, value):
        return json.dumps(value)


class JsonField(fields.AutoTypedField):
    pass


class ListField(fields.AutoTypedField):
    pass



from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six


class Json(fields.FieldType):
    def coerce(self, obj, attr, value):
        if isinstance(value, six.string_types):
            loaded = json.loads(value)
            return loaded
        return value

    def from_primitive(self, obj, attr, value):
        return self.coerce(obj, attr, value)

    def to_primitive(self, obj, attr, value):
        return json.dumps(value)


class JsonField(fields.AutoTypedField):
    AUTO_TYPE = Json()


class ListField(fields.AutoTypedField):
    AUTO_TYPE = fields.List(fields.FieldType())

Make JsonField actually do it's work
Make JsonField actually do it's work

This code will be used when objects are registered.

Change-Id: I2f1b3e2dd5584335e318b936984c227050bbe699
Partial-Bug: 1491258

  
  
  from oslo_serialization import jsonutils as json
  from oslo_versionedobjects import fields
  import six
  
  
  class Json(fields.FieldType):
      def coerce(self, obj, attr, value):
          if isinstance(value, six.string_types):
              loaded = json.loads(value)
              return loaded
          return value
  
      def from_primitive(self, obj, attr, value):
          return self.coerce(obj, attr, value)
  
      def to_primitive(self, obj, attr, value):
          return json.dumps(value)
  
  
  class JsonField(fields.AutoTypedField):
-     pass
+     AUTO_TYPE = Json()
  
  
  class ListField(fields.AutoTypedField):
-     pass
+     AUTO_TYPE = fields.List(fields.FieldType())
  
Make JsonField actually do it's work
## Code Before:


from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six


class Json(fields.FieldType):
    def coerce(self, obj, attr, value):
        if isinstance(value, six.string_types):
            loaded = json.loads(value)
            return loaded
        return value

    def from_primitive(self, obj, attr, value):
        return self.coerce(obj, attr, value)

    def to_primitive(self, obj, attr, value):
        return json.dumps(value)


class JsonField(fields.AutoTypedField):
    pass


class ListField(fields.AutoTypedField):
    pass

## Instruction:
Make JsonField actually do it's work
## Code After:


from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six


class Json(fields.FieldType):
    def coerce(self, obj, attr, value):
        if isinstance(value, six.string_types):
            loaded = json.loads(value)
            return loaded
        return value

    def from_primitive(self, obj, attr, value):
        return self.coerce(obj, attr, value)

    def to_primitive(self, obj, attr, value):
        return json.dumps(value)


class JsonField(fields.AutoTypedField):
    AUTO_TYPE = Json()


class ListField(fields.AutoTypedField):
    AUTO_TYPE = fields.List(fields.FieldType())
