22
33from typing import TYPE_CHECKING , Annotated , List , Optional , TypeVar , Union
44
5- from pydantic import BeforeValidator , Field
5+ from pydantic import AliasChoices , BeforeValidator , Field , PlainSerializer
66
77from apmodel .types .aliases import (
8+ ID_OPT_STR ,
89 JSONLD_CONTEXT ,
910 OPT_DATETIME ,
1011 OPT_STR ,
1112 OPT_STR_OR_LINK ,
1213)
1314
1415from ..context import LDContext
15- from ..helpers import generate_aliases , get_value_from_array
16+ from ..helpers import generate_aliases , get_value_from_array , to_jld
1617
1718# from ..dumper import _serialize_model_to_json
1819from ..types import ActivityPubModel
@@ -39,17 +40,15 @@ class Object(ActivityPubModel):
3940 )
4041 AS_URI = "https://www.w3.org/ns/activitystreams#Object"
4142
42- id : OPT_STR = Field (
43- validation_alias = "@id" , serialization_alias = "@id" , default = None
43+ id : ID_OPT_STR = Field (
44+ validation_alias = AliasChoices ("id" , "@id" ),
45+ serialization_alias = "@id" ,
46+ default = None ,
4447 )
4548 name : OPT_STR = Field (default = None , ** generate_aliases ("name" , "as2" ))
4649 content : OPT_STR = Field (default = None , ** generate_aliases ("content" , "as2" ))
47- summary : OPT_STR = Field (
48- default = None , ** generate_aliases ("summary" , "as2" )
49- )
50- url : OPT_STR_OR_LINK = Field (
51- default = None , ** generate_aliases ("url" , "as2" )
52- )
50+ summary : OPT_STR = Field (default = None , ** generate_aliases ("summary" , "as2" ))
51+ url : OPT_STR_OR_LINK = Field (default = None , ** generate_aliases ("url" , "as2" ))
5352 published : OPT_DATETIME = Field (
5453 alias = "https://www.w3.org/ns/activitystreams#published" , default = None
5554 )
@@ -59,74 +58,98 @@ class Object(ActivityPubModel):
5958 attributed_to : Annotated [
6059 Optional [Union [str , "Actor" , List [Union [str , "Actor" ]]]],
6160 BeforeValidator (get_value_from_array ),
61+ PlainSerializer (to_jld ()),
6262 ] = Field (
6363 alias = "https://www.w3.org/ns/activitystreams#attributedTo" , default = None
6464 )
6565 audience : Annotated [
6666 Optional [Union [str , "Object" , List [Union [str , "Object" ]]]],
6767 BeforeValidator (get_value_from_array ),
68+ PlainSerializer (to_jld ()),
6869 ] = Field (
6970 alias = "https://www.w3.org/ns/activitystreams#audience" , default = None
7071 )
7172 to : Annotated [
7273 Optional [Union [str , "Object" , List [Union [str , "Object" ]]]],
7374 BeforeValidator (get_value_from_array ),
75+ PlainSerializer (to_jld ()),
7476 ] = Field (alias = "https://www.w3.org/ns/activitystreams#to" , default = None )
7577 bto : Annotated [
7678 Optional [Union [str , "Object" , List [Union [str , "Object" ]]]],
7779 BeforeValidator (get_value_from_array ),
80+ PlainSerializer (to_jld ()),
7881 ] = Field (alias = "https://www.w3.org/ns/activitystreams#bto" , default = None )
7982 cc : Annotated [
8083 Optional [Union [str , "Object" , List [Union [str , "Object" ]]]],
8184 BeforeValidator (get_value_from_array ),
85+ PlainSerializer (to_jld ()),
8286 ] = Field (alias = "https://www.w3.org/ns/activitystreams#cc" , default = None )
8387 bcc : Annotated [
8488 Optional [Union [str , "Object" , List [Union [str , "Object" ]]]],
8589 BeforeValidator (get_value_from_array ),
90+ PlainSerializer (to_jld ()),
8691 ] = Field (alias = "https://www.w3.org/ns/activitystreams#bcc" , default = None )
8792 generator : Annotated [
88- Optional ["Object" ], BeforeValidator (get_value_from_array )
93+ Optional ["Object" ],
94+ BeforeValidator (get_value_from_array ),
95+ PlainSerializer (to_jld ()),
8996 ] = Field (
9097 alias = "https://www.w3.org/ns/activitystreams#generator" , default = None
9198 )
9299 icon : Annotated [
93- Optional ["Image" ], BeforeValidator (get_value_from_array )
100+ Optional ["Image" ],
101+ BeforeValidator (get_value_from_array ),
102+ PlainSerializer (to_jld ()),
94103 ] = Field (alias = "https://www.w3.org/ns/activitystreams#icon" , default = None )
95104 image : Annotated [
96- Optional ["Image" ], BeforeValidator (get_value_from_array )
105+ Optional ["Image" ],
106+ BeforeValidator (get_value_from_array ),
107+ PlainSerializer (to_jld ()),
97108 ] = Field (alias = "https://www.w3.org/ns/activitystreams#image" , default = None )
98109 in_reply_to : Annotated [
99- Optional ["Object" ], BeforeValidator (get_value_from_array )
110+ Optional ["Object" ],
111+ BeforeValidator (get_value_from_array ),
112+ PlainSerializer (to_jld ()),
100113 ] = Field (
101114 alias = "https://www.w3.org/ns/activitystreams#inReplyTo" , default = None
102115 )
103116 location : Annotated [
104- Optional ["Object" ], BeforeValidator (get_value_from_array )
117+ Optional ["Object" ],
118+ BeforeValidator (get_value_from_array ),
119+ PlainSerializer (to_jld ()),
105120 ] = Field (
106121 alias = "https://www.w3.org/ns/activitystreams#location" , default = None
107122 )
108123 preview : Annotated [
109- Optional ["Object" ], BeforeValidator (get_value_from_array )
124+ Optional ["Object" ],
125+ BeforeValidator (get_value_from_array ),
126+ PlainSerializer (to_jld ()),
110127 ] = Field (
111128 alias = "https://www.w3.org/ns/activitystreams#preview" , default = None
112129 )
113130 replies : Annotated [
114- Optional ["Collection" ], BeforeValidator (get_value_from_array )
131+ Optional ["Collection" ],
132+ BeforeValidator (get_value_from_array ),
133+ PlainSerializer (to_jld ()),
115134 ] = Field (
116135 alias = "https://www.w3.org/ns/activitystreams#replies" , default = None
117136 )
118137 scope : Annotated [
119- Optional ["Object" ], BeforeValidator (get_value_from_array )
138+ Optional ["Object" ],
139+ BeforeValidator (get_value_from_array ),
140+ PlainSerializer (to_jld ()),
120141 ] = Field (alias = "https://www.w3.org/ns/activitystreams#scope" , default = None )
121142 tag : Annotated [
122143 List [Union ["Object" , "Hashtag" , "Emoji" ]],
123144 BeforeValidator (get_value_from_array ),
145+ PlainSerializer (to_jld ()),
124146 ] = Field (
125147 alias = "https://www.w3.org/ns/activitystreams#tag" , default_factory = list
126148 )
127149 attachment : Annotated [
128150 List [Union ["Object" , "PropertyValue" ]],
129151 BeforeValidator (get_value_from_array ),
152+ PlainSerializer (to_jld ()),
130153 ] = Field (
131154 alias = "https://www.w3.org/ns/activitystreams#attachment" ,
132155 default_factory = list ,
0 commit comments