### Navigation

- index
- modules |
- next |
- previous |
- vSphere Automation SDK for Python 6.5.0 documentation »
- vmware Package »
- vapi Package »
- data Package »

# serializers Package

## `serializers` Package

## `cleanjson` Module

Serializer vAPI data values to clean (human readable/writable) json documents

class `vmware.vapi.data.serializers.cleanjson.``DataValueConverter`

  Bases: `object`

  Converter class that converts values from vAPI DataValue to clean JSON objects.

  static `convert_to_json`(data_value)

    Convert the given data value to a JSON string representation

    Parameters: | data_value (`vmware.vapi.data.value.DataValue`) – Data value to be converted
    Return type: | `str`
    Returns: | JSON representation of the data value

class `vmware.vapi.data.serializers.cleanjson.``DataValueToJSONEncoder`(*args, **kwargs)

  Bases: `json.encoder.JSONEncoder`

  Custon JSON encoder that converts vAPI runtime values directly into JSON string representation.

  `encode`(value)

    Encode a given vAPI runtime object

    Parameters: | value (`object`) – vAPI runtime object
    Return type: | `str`
    Returns: | JSON string

  `visit_blob_value`(value)

    Visit BlobValue

    Parameters: | value (`vmware.vapi.data.value.BlobValue`) – BlobValue object
    Return type: | `str`
    Returns: | JSON string

  `visit_default`(value)

    This is the default visit method if the type of the input value does not match any type in the keys present in dispatch map.

    Parameters: | value (`object`) – Python object
    Return type: | `str`
    Returns: | JSON string

  static `visit_double_value`(value)

    Visit a DoubleValue object

    Parameters: | value (`vmware.vapi.data.value.DoubleValue`) – Double value object
    Return type: | `str`
    Returns: | JSON string

  `visit_list`(value)

    Visit a ListValue object

    Parameters: | value (`vmware.vapi.data.value.ListValue`) – List value object
    Return type: | `str`
    Returns: | JSON string

  `visit_optional_value`(value)

    Visit a OptionalValue object

    Parameters: | value (`vmware.vapi.data.value.OptionalValue`) – Optional value object
    Return type: | `str`
    Returns: | JSON string

  `visit_primitive_value`(value)

    Visit one of StringValue, IntegerValue, BooleanValue or VoidValue

    Parameters: | value (`vmware.vapi.data.value.StringValue` (or) `vmware.vapi.data.value.IntegerValue` (or) `vmware.vapi.data.value.BooleanValue` (or) `vmware.vapi.data.value.VoidValue` (or)) – StringValue, IntegerValue, BooleanValue or VoidValue object
    Return type: | `str`
    Returns: | JSON string

  `visit_struct_value`(value)

    Visit a StructValue object

    Parameters: | value (`vmware.vapi.data.value.StructValue`) – Struct value object
    Return type: | `str`
    Returns: | JSON string

## `introspection` Module

Convenient libraries for introspection data

`vmware.vapi.data.serializers.introspection.``convert_data_def_to_data_value`(data_def)

  Convert `vmware.vapi.data.definition.DataDefinition` object to `vmware.vapi.data.value.DataValue` object. The type of the object returned is a struct value that corresponds to DataDefinition VMODL2 type present in introspection service.

  Parameters: | data_def (`vmware.vapi.data.definition.DataDefinition`) – Data definition
  Return type: | `vmware.vapi.data.value.DataValue`
  Returns: | Data value representing the data definition object

`vmware.vapi.data.serializers.introspection.``convert_data_value_to_data_def`(data_value)

  Convert `vmware.vapi.data.value.DataValue` object that corresponds to DataDefinition structure in introspection VMODL2 into `vmware.vapi.data.definition.DataDefinition` object.

  Parameters: | data_value (`vmware.vapi.data.value.DataValue`) – Data value representing the data definition object
  Return type: | `vmware.vapi.data.definition.DataDefinition`
  Returns: | Data definition

## `jsonrpc` Module

Json rpc de/serializer

exception `vmware.vapi.data.serializers.jsonrpc.``JsonRpc20Error`(code, message=None, data=None)

  Bases: `vmware.vapi.data.serializers.jsonrpc.JsonRpcError`

  json rpc 2.0 error

  Json rpc 2.0 error

  Parameters: | code (`int`) – error type that occurred message (`str`) – a short description of the error data (Primitive type / `dict` / None) – more info about the error

  `DEFAULT_MESSAGES` = {-32700: 'Parse error.', -32603: 'Internal error.', -32602: 'Invalid params.', -32601: 'Method not found.', -32600: 'Invalid Request.', -32300: 'Transport error.'}
  `INTERNAL_ERROR` = -32603
  `INVALID_PARAMS` = -32602
  `INVALID_REQUEST` = -32600
  `METHOD_NOT_FOUND` = -32601
  `PARSE_ERROR` = -32700
  `SERVER_ERROR_RANGE_MAX` = -32000
  `SERVER_ERROR_RANGE_MIN` = -32768
  `TRANSPORT_ERROR` = -32300

class `vmware.vapi.data.serializers.jsonrpc.``JsonRpc20Request`(**kwargs)

  Bases: `vmware.vapi.data.serializers.jsonrpc.JsonRpcRequest`

  Json rpc 2.0 request

  Json rpc 2.0 request init

  Parameters: | jsonrpc (`str` or None) – json rpc request version method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params id (`long` or `int` or `str` or None) – json rpc request id. Do not set for notification

  `serialize`()

    Serialize a json rpc 2.0 request

    Return type: | `str`
    Returns: | json rpc request str

  `serialize_notification`()

    Serialize a json rpc 2.0 notification

    Return type: | `str`
    Returns: | json rpc notification str

  `validate_response`(response)

    Validate a json rpc 2.0 response. Check for version / id mismatch with request

    Parameters: | response (`JsonRpcResponse`) – json rpc response object to validate

class `vmware.vapi.data.serializers.jsonrpc.``JsonRpc20Response`(**kwargs)

  Bases: `vmware.vapi.data.serializers.jsonrpc.JsonRpcResponse`

  Json rpc 2.0 response

  Json rpc 2.0 response init Either result or error must be set, but not both

  Parameters: | jsonrpc (`str` or None) – json rpc response version result (`dict`) – json rpc response dict error (`JsonRpcError` or dict) – json rpc response error id (`long` or `int` or `str`) – json rpc response id

  `serialize`()

    Serialize a json rpc 2.0 response

    Return type: | `str`
    Returns: | json rpc response str

class `vmware.vapi.data.serializers.jsonrpc.``JsonRpcDictToVapi`

  Bases: `object`

  Json rpc dict to vapi type

  Json rpc dict to vapi type init

  static `app_ctx`(ctx)

    get application context from jsonrpc dict

    Parameters: | ctx (`dict`) – json application context
    Return type: | `str`
    Returns: | operation identifier

  static `data_value`(value)

    get data value from new jsonrpc dict

    # TODO: Structure names and its fields are converted from # u’’ format to str format. This will break if we allow non # ASCII characters in the IDL

    Parameters: | value (`dict`) – json data value
    Return type: | subclass of `vmware.vapi.data.value.DataValue`
    Returns: | subclass of data value

  static `error_value`(value)

    get error value from jsonrpc dict

    Parameters: | msg (`dict`) – json error value
    Return type: | `vmware.vapi.data.value.ErrorValue`
    Returns: | error value

  static `execution_context`(ctx)

    get execution context from jsonrpc dict

    Parameters: | ctx (`dict`) – json execution context
    Return type: | `vmware.vapi.core.ExecutionContext`
    Returns: | execution context

  static `method_result`(result)

    get method result from jsonrpc dict

    Parameters: | result (`dict`) – json method result
    Return type: | `vmware.vapi.core.MethodResult`
    Returns: | method result

  static `security_ctx`(ctx)

    get security context from jsonrpc dict

    Parameters: | ctx (`dict`) – json security context
    Return type: | `vmware.vapi.core.SecurityContext`
    Returns: | json user session

exception `vmware.vapi.data.serializers.jsonrpc.``JsonRpcError`(error)

  Bases: `exceptions.Exception`

  json rpc error base class

  json rpc error base class constructor

  Parameters: | error (`dict`) – json rpc error

class `vmware.vapi.data.serializers.jsonrpc.``JsonRpcRequest`(version, method, params=None, notification=True, request_id=None)

  Bases: `object`

  Json rpc request base class

  Json rpc request base class constructor

  Parameters: | version (`str`) – json rpc request version method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params notification (`bool`) – True for notification request_id (`long` or `int` or `str` or None) – json rpc request id. Do not set for notification

  `serialize`()

    Serialize a json rpc request

    Return type: | `str`
    Returns: | json rpc request str

  `validate_response`(response)

    Validate a json rpc response. Check for version / id mismatch with request

    Parameters: | response (`JsonRpcResponse`) – json rpc response object to validate

class `vmware.vapi.data.serializers.jsonrpc.``JsonRpcResponse`(version, response_id, result, error=None)

  Bases: `object`

  Json rpc response base class

  Json rpc response base class constructor

  Parameters: | version (`str`) – json rpc response version response_id (`long` or `int` or `str` or None) – json rpc response id result (`dict`) – json rpc response dict error (`JsonRpcError`) – json rpc error

  `serialize`()

    Serialize a json rpc response

    Return type: | `str`
    Returns: | json rpc response str

class `vmware.vapi.data.serializers.jsonrpc.``VAPIJsonEncoder`(*args, **kwargs)

  Bases: `json.encoder.JSONEncoder`

  Custom JSON encoder that converts vAPI runtime types directly into JSON string representation.

  `encode`(value)

    Encode a given vAPI runtime object

    Parameters: | value (`object`) – vAPI runtime object
    Return type: | `str`
    Returns: | JSON string

  `visit_blob_value_with_type_name`(value)

    Visit BlobValue

    Parameters: | value (`vmware.vapi.data.value.BlobValue`) – BlobValue object
    Return type: | `str`
    Returns: | JSON string

  `visit_default`(value)

    This is the default visit method if the type of the input value does not match any type in the keys present in dispatch map.

    Parameters: | value (`object`) – Python object
    Return type: | `str`
    Returns: | JSON string

  `visit_dict`(value)

    Visit a dictionary. Application context and Security Context in vAPI is a free form object, so it can contain a dictionary.

    Parameters: | value (`dict`) – Dictionary value
    Return type: | `str`
    Returns: | JSON string

  static `visit_double_value`(value)

    Visit a DoubleValue object

    Parameters: | value (`vmware.vapi.data.value.DoubleValue`) – Double value object
    Return type: | `str`
    Returns: | JSON string

  `visit_execution_context`(value)

    Visit an ExecutionContext object

    Parameters: | value (`vmware.vapi.core.ExecutionContext`) – ExecutionContext object
    Return type: | `str`
    Returns: | JSON string

  `visit_list`(value)

    Visit a ListValue object

    Parameters: | value (`vmware.vapi.data.value.ListValue`) – List value object
    Return type: | `str`
    Returns: | JSON string

  `visit_method_result`(value)

    Visit a MethodResult object

    Parameters: | value (`vmware.vapi.core.MethodResult`) – MethodResult object
    Return type: | `str`
    Returns: | JSON string

  `visit_optional_value`(value)

    Visit a OptionalValue object

    Parameters: | value (`vmware.vapi.data.value.OptionalValue`) – Optional value object
    Return type: | `str`
    Returns: | JSON string

  `visit_primitive_value`(value)

    Visit one of StringValue, IntegerValue, BooleanValue or VoidValue

    Parameters: | value (`vmware.vapi.data.value.StringValue` (or) `vmware.vapi.data.value.IntegerValue` (or) `vmware.vapi.data.value.BooleanValue` (or) `vmware.vapi.data.value.VoidValue` (or)) – StringValue, IntegerValue, BooleanValue or VoidValue object
    Return type: | `str`
    Returns: | JSON string

  `visit_primitive_value_with_type_name`(value)

    Visit SecretValue

    Parameters: | value (`vmware.vapi.data.value.SecretValue`) – SecretValue object
    Return type: | `str`
    Returns: | JSON string

  `visit_struct_value`(value)

    Visit a StructValue object

    Parameters: | value (`vmware.vapi.data.value.StructValue`) – Struct value object
    Return type: | `str`
    Returns: | JSON string

`vmware.vapi.data.serializers.jsonrpc.``deserialize_request`(request_str)

  Deserialize a json rpc request

  Parameters: | request_str (`str` or `bytes:` or `file`) – json rpc request str or a file like object
  Return type: | `JsonRpcRequest`
  Returns: | json rpc request

`vmware.vapi.data.serializers.jsonrpc.``deserialize_response`(response_str)

  Deserialize a json rpc response

  Parameters: | response_str (`str` or `bytes`) – json rpc response str
  Return type: | `JsonRpcResponse`
  Returns: | json rpc response

`vmware.vapi.data.serializers.jsonrpc.``jsonrpc_request_factory`(**kwargs)

  Json rpc request factory For json 2.0: set jsonrpc to ‘2.0’ For json 1.1: set version to ‘1.1’ For json 1.0: set neither jsonrpc / version The parameters accepted depends on json version See corresponding json rpc request class for init parameters

  Parameters: | jsonrpc (`str` or None) – json rpc request version (2.0) version (`str` or None) – json rpc request version (1.1) method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params id (`long` or `int` or `str` or None) – json rpc request id. Do not set for notification
  Return type: | `JsonRpcRequest`
  Returns: | json rpc request object

`vmware.vapi.data.serializers.jsonrpc.``jsonrpc_response_factory`(**kwargs)

  Json rpc response factory For json 2.0: set jsonrpc to ‘2.0’ For json 1.1: set version to ‘1.1’ For json 1.0: set neither jsonrpc / version The parameters accepted depends on json version See corresponding json rpc response class for init parameters

  Parameters: | jsonrpc (`str` or None) – json rpc response version (2.0) version (`str` or None) – json rpc response version (1.1) method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params id (`long` or `int` or `str`) – json rpc response id
  Return type: | `JsonRpcResponse`
  Returns: | json rpc response object

`vmware.vapi.data.serializers.jsonrpc.``to_strkey_dict`(dictionary)

  Convert a unicode key dict into str key dict

  Parameters: | dictionary (`dict`) – unicode dictionary
  Return type: | `dict`
  Returns: | string key dict

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_internal_error`(data=None)

  vapi json rpc internal error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_invalid_params`(data=None)

  vapi json rpc invalid params error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_invalid_request`(data=None)

  vapi json rpc invalid request error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_method_not_found`(data=None)

  vapi json rpc method not found error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_parse_error`(data=None)

  vapi json rpc parse error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_error_transport_error`(data=None)

  vapi json rpc transport error

  Parameters: | data (`dict`) – json rpc error object
  Return type: | `JsonRpcError`
  Returns: | json rpc error object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_notification_factory`(**kwargs)

  vapi json rpc notification factory

  Parameters: | method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params
  Return type: | `JsonRpcRequest`
  Returns: | json rpc request object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_request_factory`(**kwargs)

  Json rpc request factory

  Parameters: | method (`str`) – json rpc method params (`dict` or `list` or None) – json rpc method params id (`long` or `int` or `str` or None) – json rpc request id. Do not set for notification
  Return type: | `JsonRpcRequest`
  Returns: | json rpc request object

`vmware.vapi.data.serializers.jsonrpc.``vapi_jsonrpc_response_factory`(request, **kwargs)

  vapi json rpc response factory

  Parameters: | request (`JsonRpcRequest`) – json rpc request object kwargs (`dict`) – See JsonRpc20Response for constructor parameters
  Return type: | `JsonRpcResponse`
  Returns: | json rpc response object

## `python` Module

Convenience methods to convert to/from python native values to data values

`vmware.vapi.data.serializers.python.``build_data_value`(py_value, data_def)

  Converts a native python value to data value using the provided data definition

  Parameters: | py_value (`object`) – Python native value data_def (`vmware.vapi.data.definition.DataDefinition`) – Data definition
  Return type: | `vmware.vapi.data.value.DataValue`
  Returns: | Data value

`vmware.vapi.data.serializers.python.``build_py_value`(data_value, data_def=None, impl=None)

  ” Converts a data value to python native value impl input is required to create Struct class instances

  Parameters: | data_value (`vmware.vapi.data.value.DataValue`) – Input data value data_def (`vmware.vapi.data.definition.DataDefinition` or `None`) – Data definition impl (`vmware.vapi.bindings.stub.VapiInterface` or `vmware.vapi.bindings.skeleton.VapiInterface` or `None`) – Python generated class to resolve structure classes
  Return type: | `object`
  Returns: | Native python value

## Subpackages

### Navigation

- index
- modules |
- next |
- previous |
- vSphere Automation SDK for Python 6.5.0 documentation »
- vmware Package »
- vapi Package »
- data Package »