Supporting Enum types #31
Replies: 2 comments 1 reply
-
Nice! I think it would be better if the JSON key was But perhaps it too, could be customized ? |
Beta Was this translation helpful? Give feedback.
-
This has been implemented in #48, the only difference being this point:
For such cases, no error will be generated by |
Beta Was this translation helpful? Give feedback.
-
As library is getting more adaption, it is essential to provide support for enum types as well. Currently Swift compiler's way of generating implementation:
For example enum with each case represented in JSON with Swift compiler generated implementation:
I want
MetaCodable
to behave the same way when enum case argument is provided. Following are the different behavior I have in. mind:For cases with
_
argument label is provided, argument name will be used rather than current way of using_%argumentPositionNumber
. i.e. For theSomeEnum.bool(true)
generated JSON withMetaCodable
implementation will be:For cases with single argument and no argument name the value will be directly encoded/decoded rather than being nested with
_0
key. i.e. For theSomeEnum.string("text")
generated JSON withMetaCodable
implementation will be:For cases with multiple arguments and some arguments having no name, error will be generated to provide argument name. i.e. The
SomeEnum.multi(_ variable: Bool, val: Int, String)
will be asked to be changed toSomeEnum.multi(_ variable: Bool, val: Int, strVal: String)
orSomeEnum.multi(_ variable: Bool, val: Int, _ strVal: String)
.Additionally
MetaCodable
will support following dynamic format of JSON:being represented as Enum:
Currently attaching macro to case arguments is not supported, which prevents existing features provided by
CodedAt
,CodedIn
,Default
andCodedBy
being used per enum case arguments. I have raised a request for support here, feel free to provide your reaction and support for this.Please suggest if you would like anything additional be supported or any changes to be made what has been mentioned here.
Beta Was this translation helpful? Give feedback.
All reactions