@@ -138,16 +138,19 @@ struct FieldConfig<std::optional<T>> {
138138 };
139139 return std::nullopt ;
140140 };
141- constexpr inline std::optional<std::string> Check (const std::optional<T>&) const {
141+ constexpr inline std::optional<std::string> Check (const std::optional<T>& value) const {
142+ if (value) {
143+ return this ->Main .Check (*value);
144+ };
142145 return std::nullopt ;
143146 }
144- constexpr auto Write (const std::optional<T>& value, std::string_view fieldName, const auto &, auto & builder) const {
147+ constexpr auto Write (const std::optional<T>& value, std::string_view fieldName, const auto & names , auto & builder) const {
145148 if (value) {
146- builder[ static_cast <std::string>( fieldName)] = *value ;
149+ this -> Main . Write (*value, fieldName, names, builder) ;
147150 return ;
148151 }
149152 if (this ->Default ) {
150- builder[ static_cast <std::string>(fieldName)] = this ->Default ->value ();
153+ this -> Main . Write ( this ->Default ->value (), fieldName, names, builder );
151154 return ;
152155 }
153156 }
@@ -158,10 +161,11 @@ struct FieldConfig<std::optional<T>> {
158161 return std::nullopt ;
159162 }
160163 if (!value[name].IsMissing ()) {
161- if (this ->Nullable ) {
162- return value[name].template As <std::optional<T>>();
163- }
164- return value[name].template As <T>();
164+ return this ->Nullable
165+ ? (value[name].IsNull ()
166+ ? std::nullopt
167+ : std::optional{this ->Main .template Read <MainClass, I>(std::forward<Value>(value))})
168+ : std::optional{this ->Main .template Read <MainClass, I>(std::forward<Value>(value))};
165169 }
166170 if (this ->Default ) {
167171 return this ->Default ->value ();
@@ -175,15 +179,15 @@ struct FieldConfig<std::optional<T>> {
175179 return std::nullopt ;
176180 }
177181 if (this ->Nullable ) {
178- std::optional response = parse::TryParse (value[name], parse::To< std::optional<T>>{} );
182+ std::optional response = this -> Main . template TryRead <MainClass, I>( std::forward<Value>(value) );
179183 if (response) {
180184 return response;
181185 }
182186 } else {
183187 if (value[name].IsNull ()) {
184188 return std::nullopt ;
185189 };
186- auto response = parse::TryParse (value[name], parse::To<T>{} );
190+ std::optional response = this -> Main . template TryRead <MainClass, I>(std::forward<Value>(value) );
187191 if (response) {
188192 return response;
189193 }
0 commit comments