@@ -62,6 +62,8 @@ void Serializer::setSerializerMethods() {
6262 setSerializerMethod (data::mapping::type::__class::Float64::CLASS_ID, &Serializer::serializeFloat64);
6363 setSerializerMethod (data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::serializeBoolean);
6464
65+ setSerializerMethod (data::mapping::type::__class::AbstractEnum::CLASS_ID, &Serializer::serializeEnum);
66+
6567 // //
6668
6769 setSerializerMethod (postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::serializeUuid);
@@ -89,6 +91,8 @@ void Serializer::setTypeOidMethods() {
8991 setTypeOidMethod (data::mapping::type::__class::Float64::CLASS_ID, &Serializer::getTypeOid<FLOAT8OID>);
9092 setTypeOidMethod (data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::getTypeOid<BOOLOID>);
9193
94+ setTypeOidMethod (data::mapping::type::__class::AbstractEnum::CLASS_ID, &Serializer::getEnumTypeOid);
95+
9296 // //
9397
9498 setTypeOidMethod (postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::getTypeOid<UUIDOID>);
@@ -117,7 +121,7 @@ void Serializer::serialize(OutputData& outData, const oatpp::Void& polymorph) co
117121 auto id = polymorph.valueType ->classId .id ;
118122 auto & method = m_methods[id];
119123 if (method) {
120- (*method)(outData, polymorph);
124+ (*method)(this , outData, polymorph);
121125 } else {
122126 throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serialize()]: "
123127 " Error. No serialize method for type '" + std::string (polymorph.valueType ->classId .name ) +
@@ -180,7 +184,10 @@ void Serializer::serInt8(OutputData& outData, v_int64 value) {
180184// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
181185// Serializer functions
182186
183- void Serializer::serializeString (OutputData& outData, const oatpp::Void& polymorph) {
187+ void Serializer::serializeString (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
188+
189+ (void ) _this;
190+
184191 if (polymorph) {
185192 base::StrBuffer *buff = static_cast <base::StrBuffer *>(polymorph.get ());
186193 outData.data = (char *)buff->getData ();
@@ -192,7 +199,10 @@ void Serializer::serializeString(OutputData& outData, const oatpp::Void& polymor
192199 }
193200}
194201
195- void Serializer::serializeInt8 (OutputData& outData, const oatpp::Void& polymorph) {
202+ void Serializer::serializeInt8 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
203+
204+ (void ) _this;
205+
196206 if (polymorph) {
197207 auto v = polymorph.staticCast <oatpp::Int8>();
198208 serInt2 (outData, *v);
@@ -202,7 +212,10 @@ void Serializer::serializeInt8(OutputData& outData, const oatpp::Void& polymorph
202212 }
203213}
204214
205- void Serializer::serializeUInt8 (OutputData& outData, const oatpp::Void& polymorph) {
215+ void Serializer::serializeUInt8 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
216+
217+ (void ) _this;
218+
206219 if (polymorph) {
207220 auto v = polymorph.staticCast <oatpp::UInt8>();
208221 serInt2 (outData, *v);
@@ -212,7 +225,10 @@ void Serializer::serializeUInt8(OutputData& outData, const oatpp::Void& polymorp
212225 }
213226}
214227
215- void Serializer::serializeInt16 (OutputData& outData, const oatpp::Void& polymorph) {
228+ void Serializer::serializeInt16 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
229+
230+ (void ) _this;
231+
216232 if (polymorph) {
217233 auto v = polymorph.staticCast <oatpp::Int16>();
218234 serInt2 (outData, *v);
@@ -222,7 +238,10 @@ void Serializer::serializeInt16(OutputData& outData, const oatpp::Void& polymorp
222238 }
223239}
224240
225- void Serializer::serializeUInt16 (OutputData& outData, const oatpp::Void& polymorph) {
241+ void Serializer::serializeUInt16 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
242+
243+ (void ) _this;
244+
226245 if (polymorph) {
227246 auto v = polymorph.staticCast <oatpp::UInt16>();
228247 serInt4 (outData, *v);
@@ -232,7 +251,10 @@ void Serializer::serializeUInt16(OutputData& outData, const oatpp::Void& polymor
232251 }
233252}
234253
235- void Serializer::serializeInt32 (OutputData& outData, const oatpp::Void& polymorph) {
254+ void Serializer::serializeInt32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
255+
256+ (void ) _this;
257+
236258 if (polymorph) {
237259 auto v = polymorph.staticCast <oatpp::Int32>();
238260 serInt4 (outData, *v);
@@ -242,7 +264,10 @@ void Serializer::serializeInt32(OutputData& outData, const oatpp::Void& polymorp
242264 }
243265}
244266
245- void Serializer::serializeUInt32 (OutputData& outData, const oatpp::Void& polymorph) {
267+ void Serializer::serializeUInt32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
268+
269+ (void ) _this;
270+
246271 if (polymorph) {
247272 auto v = polymorph.staticCast <oatpp::UInt32>();
248273 serInt8 (outData, *v);
@@ -252,7 +277,10 @@ void Serializer::serializeUInt32(OutputData& outData, const oatpp::Void& polymor
252277 }
253278}
254279
255- void Serializer::serializeInt64 (OutputData& outData, const oatpp::Void& polymorph) {
280+ void Serializer::serializeInt64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
281+
282+ (void ) _this;
283+
256284 if (polymorph) {
257285 auto v = polymorph.staticCast <oatpp::Int64>();
258286 serInt8 (outData, *v);
@@ -262,11 +290,17 @@ void Serializer::serializeInt64(OutputData& outData, const oatpp::Void& polymorp
262290 }
263291}
264292
265- void Serializer::serializeUInt64 (OutputData& outData, const oatpp::Void& polymorph) {
293+ void Serializer::serializeUInt64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
294+ (void ) _this;
295+ (void ) outData;
296+ (void ) polymorph;
266297 throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeUInt64()]: Error. Not implemented!" );
267298}
268299
269- void Serializer::serializeFloat32 (OutputData& outData, const oatpp::Void& polymorph) {
300+ void Serializer::serializeFloat32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
301+
302+ (void ) _this;
303+
270304 if (polymorph) {
271305 auto v = polymorph.staticCast <oatpp::Float32>();
272306 serInt4 (outData, *((p_int32) v.get ()));
@@ -276,7 +310,10 @@ void Serializer::serializeFloat32(OutputData& outData, const oatpp::Void& polymo
276310 }
277311}
278312
279- void Serializer::serializeFloat64 (OutputData& outData, const oatpp::Void& polymorph) {
313+ void Serializer::serializeFloat64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
314+
315+ (void ) _this;
316+
280317 if (polymorph) {
281318 auto v = polymorph.staticCast <oatpp::Float64>();
282319 serInt8 (outData, *((p_int64) v.get ()));
@@ -286,7 +323,10 @@ void Serializer::serializeFloat64(OutputData& outData, const oatpp::Void& polymo
286323 }
287324}
288325
289- void Serializer::serializeBoolean (OutputData& outData, const oatpp::Void& polymorph) {
326+ void Serializer::serializeBoolean (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
327+
328+ (void ) _this;
329+
290330 if (polymorph) {
291331 auto v = polymorph.staticCast <oatpp::Boolean>();
292332 outData.dataBuffer .reset (new char [1 ]);
@@ -300,7 +340,44 @@ void Serializer::serializeBoolean(OutputData& outData, const oatpp::Void& polymo
300340 }
301341}
302342
303- void Serializer::serializeUuid (OutputData& outData, const oatpp::Void& polymorph) {
343+ void Serializer::serializeEnum (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
344+
345+ auto polymorphicDispatcher = static_cast <const data::mapping::type::__class::AbstractEnum::PolymorphicDispatcher*>(
346+ polymorph.valueType ->polymorphicDispatcher
347+ );
348+
349+ data::mapping::type::EnumInterpreterError e = data::mapping::type::EnumInterpreterError::OK;
350+ const auto & enumInterpretation = polymorphicDispatcher->toInterpretation (polymorph, e);
351+
352+ if (e == data::mapping::type::EnumInterpreterError::OK) {
353+ _this->serialize (outData, enumInterpretation);
354+ return ;
355+ }
356+
357+ switch (e) {
358+ case data::mapping::type::EnumInterpreterError::CONSTRAINT_NOT_NULL:
359+ throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeEnum()]: Error. Enum constraint violated - 'NotNull'." );
360+ default :
361+ throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeEnum()]: Error. Can't serialize Enum." );
362+ }
363+
364+ }
365+
366+ Oid Serializer::getEnumTypeOid (const Serializer* _this, const oatpp::Type* type) {
367+
368+ auto polymorphicDispatcher = static_cast <const data::mapping::type::__class::AbstractEnum::PolymorphicDispatcher*>(
369+ type->polymorphicDispatcher
370+ );
371+
372+ const oatpp::Type* enumInterType = polymorphicDispatcher->getInterpretationType ();
373+ return _this->getTypeOid (enumInterType);
374+
375+ }
376+
377+ void Serializer::serializeUuid (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
378+
379+ (void ) _this;
380+
304381 if (polymorph) {
305382 auto v = polymorph.staticCast <postgresql::Uuid>();
306383 outData.data = (char *) v->getData ();
0 commit comments