1818from krrood .adapters .json_serializer import (
1919 SubclassJSONSerializer ,
2020 JSON_TYPE_NAME ,
21+ to_json ,
22+ from_json ,
2123)
2224from krrood .entity_query_language .predicate import Symbol
2325from scipy .stats import geom
@@ -87,7 +89,7 @@ def __eq__(self, other):
8789
8890
8991@dataclass
90- class CollisionCheckingConfig :
92+ class CollisionCheckingConfig ( SubclassJSONSerializer ) :
9193 buffer_zone_distance : Optional [float ] = None
9294 """
9395 Distance defining a buffer zone around the entity. The buffer zone represents a soft boundary where
@@ -111,6 +113,22 @@ class CollisionCheckingConfig:
111113 If more bodies than this are in the buffer zone, only the closest ones are avoided.
112114 """
113115
116+ def to_json (self ) -> Dict [str , Any ]:
117+ json_data = super ().to_json ()
118+ for field_ in fields (self ):
119+ value = getattr (self , field_ .name )
120+ json_data [field_ .name ] = to_json (value )
121+ return json_data
122+
123+ @classmethod
124+ def _from_json (cls , data : Dict [str , Any ], ** kwargs ) -> Self :
125+ cls_kwargs = {}
126+ for field_name , json_field_data in data .items ():
127+ if field_name == JSON_TYPE_NAME :
128+ continue
129+ cls_kwargs [field_name ] = from_json (json_field_data )
130+ return cls (** cls_kwargs )
131+
114132
115133@dataclass (unsafe_hash = True , eq = False )
116134class KinematicStructureEntity (WorldEntity , SubclassJSONSerializer , ABC ):
@@ -393,6 +411,7 @@ def to_json(self) -> Dict[str, Any]:
393411 result ["name" ] = self .name .to_json ()
394412 result ["collision" ] = self .collision .to_json ()
395413 result ["visual" ] = self .visual .to_json ()
414+ result ["collision_config" ] = to_json (self .collision_config )
396415 return result
397416
398417 @classmethod
@@ -414,6 +433,7 @@ def _from_json(cls, data: Dict[str, Any], **kwargs) -> Self:
414433
415434 result .collision = collision
416435 result .visual = visual
436+ result .collision_config = from_json (data ["collision_config" ])
417437
418438 return result
419439
0 commit comments