Is there a way to specify field names to serde at runtime?

Viewed 364

I'm trying to deserialise a JSON structure using serde, but where some of the field names can be different across different environments. For example:

In dev:

{
    "fields": {
        "field004": "This is the title",
        "field012": 456123
    }
}

In prod:

{
    "fields": {
        "field023": "This is the title",
        "field005": 456123
    }
}

Since the names do not change over time, I have them stored in an external config that can be easily retrieved into the app at runtime, but I want to avoid having to hard-code them into the structs I've build to handle the deserialisation (such as in this question) and I cannot figure out a way to get the field names retrieved from my config to be used in the deserialisation.

All other results I've found when searching for a solution to this do not address the specific problem I have.

Is there a way to specify the name of a field at runtime, or am I going to have to manually implement a deserialiser for it and use the config-fed field names that way?

0 Answers
Related