Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generated signature of toJsonProduct and fromJsonProduct #40

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions json/src/main/scala/io/sphere/json/generic/package.fmpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ package object generic {

<#list 1..22 as i>
<#assign typeParams><#list 1..i as j>A${j}<#if i !=j>,</#if></#list></#assign>
<#assign implTypeParams><#list 1..i as j>A${j} : FromJSON : ToJSON<#if i !=j>,</#if></#list></#assign>
<#assign implTypeParams><#list 1..i as j>A${j} : ToJSON<#if i !=j>,</#if></#list></#assign>
/** Creates a `ToJSON[T]` instance for a product type (case class) `T` of arity ${i}. */
def toJsonProduct[T <: Product: ClassTag, ${implTypeParams}](
construct: (<#list 1..i as j>A${j}<#if i !=j>, </#if></#list>) => T
Expand All @@ -148,7 +148,7 @@ package object generic {

<#list 1..22 as i>
<#assign typeParams><#list 1..i as j>A${j}<#if i !=j>,</#if></#list></#assign>
<#assign implTypeParams><#list 1..i as j>A${j} : FromJSON : ToJSON<#if i !=j>,</#if></#list></#assign>
<#assign implTypeParams><#list 1..i as j>A${j} : FromJSON<#if i !=j>,</#if></#list></#assign>
/** Creates a `FromJSON[T]` instance for a product type (case class) `T` of arity ${i}. */
def fromJsonProduct[T <: Product: ClassTag, ${implTypeParams}](
construct: (<#list 1..i as j>A${j}<#if i !=j>, </#if></#list>) => T
Expand Down
13 changes: 13 additions & 0 deletions json/src/test/scala/io/sphere/json/JSONSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ class JSONSpec extends FunSpec with MustMatchers {
})

}

it("must provide derived JSON instances for product types (case classes)") {
import JSONSpec.{ Project, Milestone }
// ToJSON
implicit val milestoneToJSON = toJsonProduct(Milestone.apply _)
implicit val projectToJSON = toJsonProduct(Project.apply _)
// FromJSON
implicit val milestoneFromJSON = fromJsonProduct(Milestone.apply _)
implicit val projectFromJSON = fromJsonProduct(Project.apply _)

val proj = Project(42, "Linux", 7, Milestone("1.0") :: Milestone("2.0") :: Milestone("3.0") :: Nil)
fromJSON[Project](toJSON(proj)) must equal (Valid(proj))
}
}
}

Expand Down