bhftbootcamp / Serde.jl

Serde is a Julia library for (de)serializing data to/from various formats. The library offers a simple and concise API for defining custom (de)serialization behavior for user-defined types
Apache License 2.0
31 stars 7 forks source link

Common (De)Serialization Interface #26

Closed gryumov closed 3 months ago

gryumov commented 3 months ago

Pull request checklist

gryumov commented 3 months ago

Hi @rdavis120, I'm in the process of finalizing the feature for automatically renaming fields to snake case (Issue #12). What do you think about the API design for this feature?

using Serde

struct Foo1
    first_field::Int64
    second_field::String
end

Serde.@pascal_case(Foo1)

Serde.deser_json(
    Foo1,
    "{\"FirstField\":1,\"SecondField\":\"example\"}",
)

struct Foo2
    first_field::Int64
    second_field::String
end

Serde.@camel_case(Foo2)

Serde.deser_json(
    Foo2,
    "{\"firstField\":1,\"secondField\":\"example\"}",
)

struct Foo3
    first_field::Int64
    second_field::String
end

Serde.@kebab_case(Foo3)

julia> Serde.deser_json(
           Foo3,
           "{\"first-field\":1,\"second-field\":\"example\"}",
       )
Foo3(1, "example")