@@ -623,31 +623,29 @@ def __repr__(self) -> str:
623
623
return f'<CallStack frames={ len (self .frames )} >'
624
624
625
625
626
- class _IdentitySerializationHelper (serializable .helpers .BaseHelper ):
626
+ class _IdentityRepositorySerializationHelper (serializable .helpers .BaseHelper ):
627
627
"""THIS CLASS IS NON-PUBLIC API"""
628
628
629
629
@classmethod
630
630
def json_normalize (cls , o : SortedSet [Identity ], * ,
631
631
view : Optional [type [serializable .ViewType ]],
632
- ** __ : Any ) -> Any :
632
+ ** __ : Any ) -> Union [ dict , list [ dict ], None ] :
633
633
if not o :
634
634
return None
635
-
636
- # For Schema 1.5 JSON, return first identity as a single object
637
- if view and issubclass (view , SchemaVersion1Dot5 ):
638
- first_identity = next (iter (o ))
635
+ if view and view is SchemaVersion1Dot5 :
636
+ # For Schema 1.5 JSON, return first identity as a single object
637
+ first_identity = o [0 ]
639
638
return json_loads (first_identity .as_json (view_ = view )) # type: ignore[attr-defined]
640
-
641
639
# For Schema 1.6 and others, return array of all identities
642
640
return [json_loads (identity .as_json (view_ = view )) for identity in o ] # type: ignore[attr-defined]
643
641
644
642
@classmethod
645
- def json_denormalize (cls , o : Any , ** __ : Any ) -> SortedSet [ Identity ]:
643
+ def json_denormalize (cls , o : Any , ** __ : Any ) -> Optional [ list [ Identity ] ]:
646
644
if isinstance (o , dict ): # Single Identity object (Schema 1.5)
647
- return SortedSet ( [Identity .from_json (o )]) # type: ignore[attr-defined]
645
+ return [Identity .from_json (o )] # type: ignore[attr-defined]
648
646
elif isinstance (o , (list , tuple )): # Array of Identity objects (Schema 1.6)
649
- return SortedSet ( Identity .from_json (i ) for i in o ) # type: ignore[attr-defined]
650
- return SortedSet ()
647
+ return [ Identity .from_json (i ) for i in o ] # type: ignore[attr-defined]
648
+ return None
651
649
652
650
653
651
@serializable .serializable_class
@@ -679,7 +677,7 @@ def __init__(
679
677
@serializable .view (SchemaVersion1Dot5 )
680
678
@serializable .view (SchemaVersion1Dot6 )
681
679
@serializable .xml_sequence (1 )
682
- @serializable .type_mapping (_IdentitySerializationHelper )
680
+ @serializable .type_mapping (_IdentityRepositorySerializationHelper )
683
681
@serializable .xml_array (serializable .XmlArraySerializationType .FLAT , 'identity' )
684
682
# TODO: CDX 1.5 knows only one identity, all versions later known multiple ...
685
683
# TODO: need to fix the serialization/normalization
0 commit comments