lukewilliamboswell / roc-json

Json package for Roc
https://lukewilliamboswell.github.io/roc-json/
Universal Permissive License v1.0
21 stars 13 forks source link

Config options have no effect on object in array decoding #13

Closed WhileTruu closed 7 months ago

WhileTruu commented 7 months ago

The following expectations fail when decoding an array of objects:

Field name mapping is not used

expect
    input = Str.toUtf8 "[{\"field_name\":1}]"

    decoder = jsonWithOptions { fieldNameMapping: SnakeCase }

    actual : DecodeResult (List { fieldName : U64 })
    actual = Decode.fromBytesPartial input decoder

    expected = Ok [{ fieldName: 1 }]

    actual.result == expected

Missing properties are skipped

expect
    input = Str.toUtf8 "[{\"extraField\":2,\"fieldName\":1}]"

    decoder = jsonWithOptions { skipMissingProperties: Bool.false }

    actual : DecodeResult (List { fieldName : U64 })
    actual = Decode.fromBytesPartial input decoder

    expected = Err TooShort

    actual.result == expected
lukewilliamboswell commented 7 months ago

I think I can see the issue here, it should take the arguments like in here I think.

I think I may not be able to look at this for a few days.