-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from tethys-json/either-writer
Implement JsonWriter for Either
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
modules/core/src/main/scala/tethys/writers/instances/EitherWriters.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,22 @@ | ||
package tethys.writers.instances | ||
|
||
import tethys.JsonWriter | ||
import tethys.writers.tokens.TokenWriter | ||
|
||
private[tethys] trait EitherWriters { | ||
implicit def eitherWriter[L, R](implicit L: JsonWriter[L], R: JsonWriter[R]): JsonWriter[Either[L, R]] = new JsonWriter[Either[L, R]] { | ||
override def write(name: String, value: Either[L, R], tokenWriter: TokenWriter): Unit = { | ||
value match { | ||
case Left(left) => L.write(name, left, tokenWriter) | ||
case Right(right) => R.write(name, right, tokenWriter) | ||
} | ||
} | ||
|
||
def write(value: Either[L, R], tokenWriter: TokenWriter): Unit = { | ||
value match { | ||
case Left(left) => L.write(left, tokenWriter) | ||
case Right(right) => R.write(right, tokenWriter) | ||
} | ||
} | ||
} | ||
} |
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