-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rearranged and mapped some of the semi-autos from circe.derivation
- Loading branch information
Showing
7 changed files
with
76 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
generic-extras/src/main/scala-2/io/circe/generic/extras/auto/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.circe.generic.extras | ||
|
||
/** | ||
* Fully automatic configurable codec derivation. | ||
* | ||
* Importing the contents of this package object provides [[io.circe.Decoder]] and [[io.circe.Encoder]] instances for | ||
* case classes (if all members have instances), "incomplete" case classes, sealed trait hierarchies, etc. | ||
*/ | ||
package object auto extends AutoDerivation |
14 changes: 6 additions & 8 deletions
14
generic-extras/src/main/scala-2/io/circe/generic/extras/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package io.circe.generic.extras | ||
package io.circe.generic | ||
|
||
/** | ||
* Fully automatic configurable codec derivation. | ||
* | ||
* Importing the contents of this package object provides [[io.circe.Decoder]] and [[io.circe.Encoder]] instances for | ||
* case classes (if all members have instances), "incomplete" case classes, sealed trait hierarchies, etc. | ||
*/ | ||
package object auto extends AutoDerivation | ||
import io.circe.Codec | ||
|
||
package object extras { | ||
type ExtrasAsObjectCodec[A] = Codec.AsObject[A] with ExtrasDecoder[A] | ||
} |
51 changes: 51 additions & 0 deletions
51
generic-extras/src/main/scala-3/io/circe/generic/extras/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.circe.generic | ||
|
||
import io.circe.Codec | ||
import java.util.regex.Pattern | ||
|
||
package object extras { | ||
type ExtrasAsObjectCodec[A] = Codec.AsObject[A] with ExtrasDecoder[A] | ||
type Configuration = io.circe.derivation.Configuration | ||
|
||
object Configuration { | ||
def apply( | ||
transformMemberNames: String => String = Predef.identity, | ||
transformConstructorNames: String => String = Predef.identity, | ||
useDefaults: Boolean = false, | ||
discriminator: Option[String] = None, | ||
strictDecoding: Boolean = false | ||
): Configuration = Configuration( | ||
transformMemberNames = transformMemberNames, | ||
transformConstructorNames = transformConstructorNames, | ||
useDefaults = useDefaults, | ||
discriminator = discriminator, | ||
strictDecoding = strictDecoding | ||
) | ||
|
||
val default: Configuration = io.circe.derivation.Configuration.default | ||
private val basePattern: Pattern = Pattern.compile("([A-Z]+)([A-Z][a-z])") | ||
private val swapPattern: Pattern = Pattern.compile("([a-z\\d])([A-Z])") | ||
|
||
val snakeCaseTransformation: String => String = s => { | ||
val partial = basePattern.matcher(s).replaceAll("$1_$2") | ||
swapPattern.matcher(partial).replaceAll("$1_$2").toLowerCase | ||
} | ||
|
||
val screamingSnakeCaseTransformation: String => String = s => { | ||
val partial = basePattern.matcher(s).replaceAll("$1_$2") | ||
swapPattern.matcher(partial).replaceAll("$1_$2").toUpperCase | ||
} | ||
|
||
val kebabCaseTransformation: String => String = s => { | ||
val partial = basePattern.matcher(s).replaceAll("$1-$2") | ||
swapPattern.matcher(partial).replaceAll("$1-$2").toLowerCase | ||
} | ||
|
||
val pascalCaseTransformation: String => String = s => { | ||
s"${s.charAt(0).toUpper}${s.substring(1)}" | ||
} | ||
} | ||
object defaults { | ||
implicit val defaultGenericConfiguration: Configuration = Configuration.default | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
generic-extras/src/main/scala/io/circe/generic/extras/package.scala
This file was deleted.
Oops, something went wrong.