j2labs/dictshield — Issue #22: Feature idea/request: support for naming convention transforms
Author: alexanderdean
Created: 2011-10-28 23:47:32+00:00
State: open

Naming convention transforms are a common feature in serialisation libs (e.g. Java Jackson) and ORMs (e.g. Python SQLalchemy and Scala Squeryl). The basic idea is to support different naming conventions (e.g. camelCase, snake_case) expressed in the JSON/SQL table/whatever, without having to breach the style guide of the host language.

At the moment with Dictshield, if I have a JSON which contains `updatedAt` and `createdAt`, then I need to rename my Python fields to match - I can't use `updated_at` and `created_at`.

The Squeryl way of supporting this is really DRY:

// Auto-translate Scala camelCase field names into lower_underscore field names
override def columnNameFromPropertyName(n:String) =
SquerylNamingConventionTransforms.camelCase2LowerUnderscore(n)

The SQLalchemy conversion functions are in [model_generator.py](https://bitbucket.org/marcinkuzminski/sqlalchemy-model-generator/src/9d2eeced50eb/model_generator.py)

Jerkson (Scala Jackson) uses a `@JsonSnakeCase` annotation per-field, powered by a [snakeCase](https://github.com/codahale/jerkson/blob/development/src/main/scala/com/codahale/jerkson/Util.scala) method.