Parsing Key
This field provides a way of renaming a class property or enum case for parsing purposes.
When would I use it?
Well in an ideal scenario, never. But that's not how software development works.
A typical use case would be when you start using OneGen for an existing application. Not all the parsing keys likely use the same names as your models. Sometimes, the JSON parsing of legacy software gets messy over time, and you could find multiple naming conventions used. Other times you wish you could rename a JSON field, but it'd just be too much headache if it's already being used in production.
Another use case could be a dependency on a third-party SDK.
You wouldn't want these issues to dictate your model naming conventions in favor of an existing JSON design. This is where the parsing key comes in. When OneGen generates the model code, if there's a parsing key, the generated JSON parsing code will use it to bridge the gap between your model name and the parsing name.
Why not just use the name attribute?
If you read about the name attribute, you might be wondering why not just use that instead of a parsing key?
Two reasons:
- The name attribute is not shared between engines, so you can't set it in the design module
- The name attribute is applied to the model, not the parsing code. The parsing would still use the id of the given property/case.