@@ -23,8 +23,9 @@ static bool mapRaw(const json::Value &Params, StringLiteral Prop,
2323 P.report (" expected object" );
2424 return false ;
2525 }
26- if (const json::Value *E = O->get (Prop))
27- V = std::move (Params);
26+ const json::Value *E = O->get (Prop);
27+ if (E)
28+ V = std::move (*E);
2829 return true ;
2930}
3031
@@ -103,13 +104,18 @@ json::Value toJSON(const Response &R) {
103104
104105 if (R.message ) {
105106 assert (!R.success && " message can only be used if success is false" );
106- switch (*R.message ) {
107- case Response::Message::cancelled:
108- Result.insert ({" message" , " cancelled" });
109- break ;
110- case Response::Message::notStopped:
111- Result.insert ({" message" , " notStopped" });
112- break ;
107+ if (const auto *messageEnum = std::get_if<Response::Message>(&*R.message )) {
108+ switch (*messageEnum) {
109+ case Response::Message::cancelled:
110+ Result.insert ({" message" , " cancelled" });
111+ break ;
112+ case Response::Message::notStopped:
113+ Result.insert ({" message" , " notStopped" });
114+ break ;
115+ }
116+ } else if (const auto *messageString =
117+ std::get_if<std::string>(&*R.message )) {
118+ Result.insert ({" message" , *messageString});
113119 }
114120 }
115121
@@ -119,7 +125,8 @@ json::Value toJSON(const Response &R) {
119125 return std::move (Result);
120126}
121127
122- bool fromJSON (json::Value const &Params, Response::Message &M, json::Path P) {
128+ bool fromJSON (json::Value const &Params,
129+ std::variant<Response::Message, std::string> &M, json::Path P) {
123130 auto rawMessage = Params.getAsString ();
124131 if (!rawMessage) {
125132 P.report (" expected a string" );
@@ -130,11 +137,10 @@ bool fromJSON(json::Value const &Params, Response::Message &M, json::Path P) {
130137 .Case (" cancelled" , Response::Message::cancelled)
131138 .Case (" notStopped" , Response::Message::notStopped)
132139 .Default (std::nullopt );
133- if (!message) {
134- P.report (" unexpected value, expected 'cancelled' or 'notStopped'" );
135- return false ;
136- }
137- M = *message;
140+ if (message)
141+ M = *message;
142+ else if (!rawMessage->empty ())
143+ M = rawMessage->str ();
138144 return true ;
139145}
140146
@@ -223,7 +229,7 @@ bool fromJSON(json::Value const &Params, Event &E, json::Path P) {
223229
224230 MessageType type;
225231 int64_t seq;
226- if (!O.map (" type" , type) || !O.map (" seq" , seq) || O.map (" event" , E.event ))
232+ if (!O.map (" type" , type) || !O.map (" seq" , seq) || ! O.map (" event" , E.event ))
227233 return false ;
228234
229235 if (type != MessageType::event) {
0 commit comments