amnaredo / test

0 stars 0 forks source link

Fields transformers #120

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

Json4s enables users to rewrite both keys and values with their FieldSerializers (cf. https://github.com/json4s/json4s#serializing-fields-of-a-class) I use it to transform camelCase to underscore_case with something like this:

 private def camelToUnderscores(name: String) = "[A-Z]".r.replaceAllIn(name, {m =>
    "_" + m.group(0).toLowerCase()
  })

  val camelCaseToUnderscoreSerializer = FieldSerializer[TypedComponent](
  { case (key,v) => Some(camelToUnderscores(key),v) }
  )

implicit val formats = DefaultFormats + camelCaseToUnderscoreSerializer

I don't know if it is something you want in your roadmap though. If you do, can you point me where I should look at to try to make a PR?

ID: 80 Original Author: knshiro

amnaredo commented 3 years ago

I don't know what this is or how it would be useful. Perhaps we could talk in the gitter channel? https://gitter.im/lihaoyi/upickle

Original Author: lihaoyi