@@ -11,6 +11,7 @@ import ParseSwift
1111extension ParseHookFunctionRequest : Content { }
1212extension ParseHookTriggerRequest : Content { }
1313extension ParseHookResponse : Content { }
14+
1415public extension ParseHookRequestable {
1516 /**
1617 Produce the set of options that should be used for subsequent `ParseHook` requests.
@@ -53,3 +54,55 @@ public extension ParseHookRequestable {
5354 return try await self . hydrateUser ( options: updatedOptions)
5455 }
5556}
57+
58+ extension ParseEncoder : ContentEncoder {
59+
60+ public func encode< E> (
61+ _ encodable: E ,
62+ to body: inout ByteBuffer ,
63+ headers: inout HTTPHeaders
64+ ) throws where E: Encodable {
65+ try self . encode (
66+ encodable,
67+ to: & body,
68+ headers: & headers,
69+ userInfo: [ : ]
70+ )
71+ }
72+
73+ public func encode< E> (
74+ _ encodable: E ,
75+ to body: inout ByteBuffer ,
76+ headers: inout HTTPHeaders ,
77+ userInfo: [ CodingUserInfoKey : Sendable ]
78+ ) throws where E: Encodable {
79+ headers. contentType = . json
80+ let jsonEncoder = User . getJSONEncoder ( )
81+
82+ if !userInfo. isEmpty {
83+ try body. writeBytes ( JSONEncoder . custom (
84+ dates: jsonEncoder. dateEncodingStrategy,
85+ data: jsonEncoder. dataEncodingStrategy,
86+ keys: jsonEncoder. keyEncodingStrategy,
87+ format: jsonEncoder. outputFormatting,
88+ floats: jsonEncoder. nonConformingFloatEncodingStrategy,
89+ userInfo: jsonEncoder. userInfo. merging ( userInfo) { $1 }
90+ ) . encode ( encodable) )
91+ } else {
92+ if let parseEncodable = encodable as? ParseCloudTypeable {
93+ try body. writeBytes ( self . encode ( parseEncodable, skipKeys: . cloud) )
94+ } else if let parseEncodable = encodable as? ParseEncodable {
95+ let skipKeys : SkipKeys
96+ if !ParseSwift. configuration. isRequiringCustomObjectIds {
97+ skipKeys = . object
98+ } else {
99+ skipKeys = . customObjectId
100+ }
101+ try body. writeBytes ( self . encode ( parseEncodable, skipKeys: skipKeys) )
102+ } else {
103+ try body. writeBytes ( jsonEncoder. encode ( encodable) )
104+ }
105+
106+ }
107+ }
108+ }
0 commit comments