a= {'message_id': '0b35dea6-23fe-44cc-a5a6-0f64a5eb382c', 'var_a': '8', 'var_b': 'False'}
Give the dictionary above, how do I convert the dictionary with string literal back to attribute types in dataclass?
I have a dataclass in MessageHeaders
like below:
@dataclass
class MessageHeader:
message_id: uuid.UUID
var_a: int
var_b: bool
This is how I convert dictionary to dataclass:
MessageHeader(**a)
However, it is not ideal as all the attributes would be in string (not in the attribute type)
What is the best approach to convert dictionary (string type) to the dataclass matching attribute type?