Skip to content

Commit 95e940b

Browse files
committed
added methods Type_Safe.bytes and Json.json_to_bytes
1 parent 3451b25 commit 95e940b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

osbot_utils/base_classes/Type_Safe.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
1515
from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
1616
from osbot_utils.utils.Dev import pprint
17-
from osbot_utils.utils.Json import json_parse
17+
from osbot_utils.utils.Json import json_parse, json_to_bytes
1818
from osbot_utils.utils.Misc import list_set
1919
from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
2020
raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
@@ -230,9 +230,13 @@ def __schema__(cls):
230230
# global methods added to any class that base classes this
231231
# todo: see if there should be a prefix on these methods, to make it easier to spot them
232232
# of if these are actually that useful that they should be added like this
233+
def bytes(self):
234+
return json_to_bytes(self.json())
235+
233236
def json(self):
234237
return self.serialize_to_dict()
235238

239+
236240
def merge_with(self, target):
237241
original_attrs = {k: v for k, v in self.__dict__.items() if k not in target.__dict__} # Store the original attributes of self that should be retained.
238242
self.__dict__ = target.__dict__ # Set the target's __dict__ to self, now self and target share the same __dict__.

osbot_utils/utils/Json.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def json_save_tmp_file(python_object, pretty=True):
158158
json_lines_loads = Json.loads_json_lines
159159
json_parse = Json.loads
160160
json_lines_parse = Json.loads_json_lines
161+
json_to_bytes = json_dumps_to_bytes
161162
json_to_str = json_dumps
162163
json_round_trip = Json.round_trip
163164
json_save = Json.save_file

0 commit comments

Comments
 (0)