-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write/Read nested objects #39
Comments
This use case might be solved by the addition of |
Here's a let inline (|PropertyWith|) fromJson key =
Lens.getPartial (Json.Object_ >??> key_ key)
>> Option.bind (fromJson >> function | Value a, _ -> Some a
| _, _ -> None) |
No problem, I'll get that in very soon - useful addition. There's likely to be a new Aether and Chiron (better in some serious ways I hope) out very soon, I'm kind of considering this weekend... |
Awesome. Beware that I've lost the connection with the API changes you've done to Aether (haven't seen any docs either), so I'm currently only using older versions of it. |
Yeah new docs do need to be done before a release actually... I think I How are you using Aether at the moment? If a library, then the new changes On 4 December 2015 at 13:13, Henrik Feldt [email protected] wrote:
|
In Suave, in proprietary software, in Logary v4 mostly. |
Cool. Well if you're usually pulling it in as a library, then it should be fine. And obviously it'll be a new major version, so if you've pinned things also no problem. |
I'm thinking of using it like this: type PointValue =
/// Value at point in time
| Gauge of Value * Units
/// Any sort of derived measure
| Derived of Value * Units
/// All simple-valued fields' values can be templated into the template string
/// when outputting the value in the target.
| Event of template:string
with
static member private valueUnitsToJson (value : Value, units : Units) : Json<unit> =
Json.write "value" value
*> Json.write "units" units
static member private valueUnitsFromJson : Json<Value * Units> =
(fun value units -> value, units)
<!> Json.read "value"
<*> Json.read "units"
static member ToJson (pv : PointValue) : Json<unit> =
let inJsonObject writer =
writer (Json.Object Map.empty) |> snd
match pv with
| Gauge (value, units) ->
Json.writeWith (PointValue.valueUnitsToJson >> inJsonObject) "gauge" (value, units)
| Derived (value, units) ->
Json.writeWith (PointValue.valueUnitsToJson >> inJsonObject) "derived" (value, units)
| Event template ->
Json.write "event" template |
That seems pretty sensible. |
This has been merged in, and is out in 8.0.0-rc4 - definitely take a look at getting the latest. There's a backwards compat layer, but the new version is nicer when switched! |
I often have a tuple in F# 3-5 items long, but want to serialise it as an object;
then I need to do lots of shenanigans.
With these I don't:
Means I can have this usage:
What about adding them to the project?
The text was updated successfully, but these errors were encountered: