-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: using codedecider to choose correct codec from contenttype
- Loading branch information
1 parent
a8413a9
commit b5cf9c4
Showing
3 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
smithy4play/src/main/scala/de/innfactory/smithy4play/CodecDecider.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,31 @@ | ||
package de.innfactory.smithy4play | ||
|
||
import smithy4s.codecs.{ PayloadDecoder, PayloadEncoder } | ||
import smithy4s.schema.CachedSchemaCompiler | ||
import smithy4s.xml.Xml | ||
|
||
object CodecDecider { | ||
|
||
def encoder( | ||
contentType: Seq[String] | ||
)(implicit encoder: CachedSchemaCompiler[PayloadEncoder]): CachedSchemaCompiler[PayloadEncoder] = | ||
contentType match { | ||
case Seq("application/json") => encoder | ||
case Seq("application/xml") => Xml.encoders | ||
case _ => | ||
CachedSchemaCompiler | ||
.getOrElse(smithy4s.codecs.StringAndBlobCodecs.encoders, encoder) | ||
} | ||
|
||
def decoder( | ||
contentType: Seq[String] | ||
)(implicit decoder: CachedSchemaCompiler[PayloadDecoder]): CachedSchemaCompiler[PayloadDecoder] = | ||
contentType match { | ||
case Seq("application/json") => decoder | ||
case Seq("application/xml") => Xml.decoders | ||
case _ => | ||
CachedSchemaCompiler | ||
.getOrElse(smithy4s.codecs.StringAndBlobCodecs.decoders, decoder) | ||
} | ||
|
||
} |
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
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