dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

Different field_name on different object returned

Open Dvergatal opened this issue 2 years ago • 0 comments

I am currently struggling with a difficult problem to solve. because what i want to do is to prepare a data class for azure cloud to i.e. update device attestation.

The problem which I'm facing is that a sample request for i.e. Symmetric Key looks like this:

{
  "type": "symmetricKey",
  "symmetricKey": {
    "primaryKey": "<primary key>",
    "secondaryKey": "<secondary key>"
  }
}

as you can see in another json code block for i.e. TPM:

{
  "type": "tpm",
  "tpm": {
    "endorsementKey": "<endorsement key>"
  }
}

you can see that the second field changes according to the name of class. Now I have these classes written and have a factory function returning, specified by this first type variable, object. The problem which I'm facing is that the name of this object in json is the name of variable not the name of the returned object type. I was thinking of using this field_name parameter from the field module, in order to change it's name but it's not possible, or maybe i dunno how to do that, to change it depending on the returned object type.

I would be pleased if somebody might have a solution for this use case.

Dvergatal avatar May 03 '22 16:05 Dvergatal