Пример #1
0
def _convert_java_value(kv, include_non_primitives=True):
    try:
        pobj = javaobj.loads(kv.serialized_value)
        if pyutils.is_str_instance(pobj):
            return pobj

        if pobj.is_primitive():
            return pobj.value

        if include_non_primitives:
            # java objects that are not strings return value and encoded value
            # Hexadecimal byte array for Serialized objects that
            return {
                'value':
                json.dumps(pobj,
                           default=lambda custom_field: custom_field.__dict__,
                           sort_keys=True,
                           indent=2),
                'raw':
                utils.hex_escape(kv.serialized_value)
            }

        return None
    except Exception:
        Log.exception("Failed to parse data as java object")
        if include_non_primitives:
            return _raw_value(kv)
        else:
            return None
Пример #2
0
def _convert_java_value(kv, include_non_primitives=True):
  try:
    pobj = javaobj.loads(kv.serialized_value)
    if pyutils.is_str_instance(pobj):
      return pobj

    if pobj.is_primitive():
      return pobj.value

    if include_non_primitives:
      # java objects that are not strings return value and encoded value
      # Hexadecimal byte array for Serialized objects that
      return {
          'value' : json.dumps(pobj,
                               default=lambda custom_field: custom_field.__dict__,
                               sort_keys=True,
                               indent=2),
          'raw' : utils.hex_escape(kv.serialized_value)}

    return None
  except Exception:
    Log.exception("Failed to parse data as java object")
    if include_non_primitives:
      return _raw_value(kv)
    else:
      return None