@@ -49,18 +49,29 @@ function shutdown(s::ZMQ.Socket, ctx::ZMQ.Context)
4949 return ZMQ. close (ctx)
5050end
5151
52+ """
53+ serialize_response(ret)
54+
55+ Serialize the return value `ret` of a Wflow BMI function to a JSON string. JSON has no
56+ representation for the non-finite floating point values `NaN`, `Inf` and `-Inf`, so these
57+ are encoded as `null`.
58+ """
59+ function serialize_response (ret)
60+ return JSON. json (ret; allownan = true , nan = " null" , inf = " null" , ninf = " null" )
61+ end
62+
5263" Error response ZMQ server"
5364function response (err:: AbstractString , s:: ZMQ.Socket )
5465 @info " Send error response"
5566 resp = Dict {String, String} (" status" => " ERROR" , " error" => err)
56- return ZMQ. send (s, JSON3 . write (resp))
67+ return ZMQ. send (s, JSON . json (resp))
5768end
5869
5970" Status response ZMQ server"
6071function response (s:: ZMQ.Socket )
6172 @info " Send status response"
6273 resp = Dict {String, String} (" status" => " OK" )
63- return ZMQ. send (s, JSON3 . write (resp))
74+ return ZMQ. send (s, JSON . json (resp))
6475end
6576
6677" Validate JSON request against mapped Struct"
@@ -89,7 +100,7 @@ function wflow_bmi(s::ZMQ.Socket, handler::ModelHandler, f)
89100 response (s)
90101 else
91102 @info " Send response including output from Wflow function `$(f. fn) `"
92- ZMQ. send (s, JSON3 . write (ret; allow_inf = true ))
103+ ZMQ. send (s, serialize_response (ret))
93104 end
94105 catch e
95106 @error " Wflow function `$(f. fn) ` failed" exception = (e, catch_backtrace ())
@@ -151,13 +162,13 @@ function start(port::Int)
151162 while true
152163 # Wait for next request from client
153164 req = ZMQ. recv (socket)
154- json = JSON3 . read (req; allow_inf = true )
165+ json = JSON . parse (req; allownan = true )
155166 @info " Received request to run function `$(json. fn) `..."
156167
157168 if haskey (MAP_STRUCTS, json. fn)
158169 v = valid_request (json)
159170 if isnothing (v)
160- f = StructTypes . constructfrom ( MAP_STRUCTS[json. fn], json )
171+ f = JSON . parse (req, MAP_STRUCTS[json. fn]; allownan = true )
161172 wflow_bmi (socket, handler, f)
162173 else
163174 err = (
0 commit comments