Skip to content

Commit

Permalink
accept null as empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
aewering committed Feb 24, 2024
1 parent 9e9d8a4 commit 158eeca
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 57 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ Below is a list which ones have been implemented so far.
- Using json_name option to override field names ✔️
- Enum decoding via enum variant names in .proto file ✔️
- Enum decoding via field numbers in .proto file ✔️
- Accepting `null` as the empty list ❌
- Accepting `Infinity`, `-Infinity`, `NaN` as floats ❌
- Accepting `null` as the empty list ✔️
- Accepting `Infinity`, `-Infinity`, `NaN` as floats/doubles ❌
- Accepting floats/doubles in String format ❌
- Accepting floats/doubles in Exponent Notation ❌
- Encoding/Decoding Timestamps in ISO Format ✔️
- Encoding/Decoding Durations in fractional second-based format ❌
- Encoding/Decoding `google.protobuf.Struct` as a JSON object ✔️
Expand Down
5 changes: 4 additions & 1 deletion src/Generator/Message.elm
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ toJsonDecoder ( fieldName, field ) =
C.apply
[ Meta.JsonDecode.field
, C.string fieldName.jsonName
, C.apply [ Meta.JsonDecode.list, fieldTypeToJsonDecoder fieldType cardinality ]
, Meta.JsonDecode.oneOf
[ C.apply [ Meta.JsonDecode.list, fieldTypeToJsonDecoder fieldType cardinality ]
, C.apply [ Meta.JsonDecode.null, C.list [] ]
]
]

MapField _ key value ->
Expand Down
18 changes: 15 additions & 3 deletions src/Proto/Google/Protobuf/Compiler/Internals_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ jsonDecodeProto__Google__Protobuf__Compiler__CodeGeneratorResponse =
)
(Json.Decode.field
"file"
(Json.Decode.list jsonDecodeProto__Google__Protobuf__Compiler__CodeGeneratorResponse__File)
(Json.Decode.oneOf
[ Json.Decode.list jsonDecodeProto__Google__Protobuf__Compiler__CodeGeneratorResponse__File
, Json.Decode.null []
]
)
)


Expand Down Expand Up @@ -288,11 +292,19 @@ jsonDecodeProto__Google__Protobuf__Compiler__CodeGeneratorRequest :
jsonDecodeProto__Google__Protobuf__Compiler__CodeGeneratorRequest =
Json.Decode.map4
Proto__Google__Protobuf__Compiler__CodeGeneratorRequest
(Json.Decode.field "fileToGenerate" (Json.Decode.list Json.Decode.string))
(Json.Decode.field
"fileToGenerate"
(Json.Decode.oneOf [ Json.Decode.list Json.Decode.string, Json.Decode.null [] ])
)
(Json.Decode.maybe (Json.Decode.field "parameter" Json.Decode.string) |> Json.Decode.map (Maybe.withDefault ""))
(Json.Decode.field
"protoFile"
(Json.Decode.list Proto.Google.Protobuf.Internals_.jsonDecodeProto__Google__Protobuf__FileDescriptorProto)
(Json.Decode.oneOf
[ Json.Decode.list
Proto.Google.Protobuf.Internals_.jsonDecodeProto__Google__Protobuf__FileDescriptorProto
, Json.Decode.null []
]
)
)
(Json.Decode.maybe
(Json.Decode.field
Expand Down
Loading

0 comments on commit 158eeca

Please sign in to comment.