Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
Open
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: 3 additions & 1 deletion src/main/scala/jacks/module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ class ScalaTypeSig(val tf: TypeFactory, val `type`: JavaType, val sig: ScalaSig)
import tools.scalap.scalax.rules.scalasig.{Method => _, _}
import ScalaTypeSig.findClass

def path(c:ClassSymbol) = c.path.replaceFirst("^<empty>\\.", "")

val cls = {
val name = `type`.getRawClass.getCanonicalName.replace('$', '.')
sig.symbols.collectFirst {
case c:ClassSymbol if c.path == name => c
case c:ClassSymbol if path(c) == name && !c.isModule => c
}.get
}

Expand Down
22 changes: 21 additions & 1 deletion src/test/scala/jacks/test.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (C) 2011 - Will Glozer. All rights reserved.

package com.lambdaworks.jacks
case class Point(x: Int, y: Int)

package com.lambdaworks.jacks {

import com.fasterxml.jackson.annotation._
import com.fasterxml.jackson.annotation.JsonInclude.Include
Expand Down Expand Up @@ -89,6 +91,10 @@ case class NamingStrategy(camelCase: String, PascalCase: Int)

case class WithAny(map: Map[String, Any])

object ObjectBeforeCaseClass

case class ObjectBeforeCaseClass(x: Int)

class CaseClassSuite extends JacksTestSuite {
test("primitive types correct") {
rw(Primitives(boolean = false)) should equal (Primitives(boolean = false))
Expand Down Expand Up @@ -215,6 +221,17 @@ class CaseClassSuite extends JacksTestSuite {
val map = Map[String, Any]("foo" -> 1, "bar" -> "2")
rw(WithAny(map)) should equal (WithAny(map))
}

test("Works correctly when companion object is before the case class") {
val obcc = ObjectBeforeCaseClass(5)
rw(obcc) should equal (obcc)
}

test("Works correctly when case class is in root package") {
val point = Point(5, 7)
rw(point) should equal (point)
}

}

class InvalidJsonSuite extends JacksTestSuite {
Expand Down Expand Up @@ -298,3 +315,6 @@ trait JacksTestSuite extends FunSuite with Matchers {
def write[T: Manifest](v: T) = writeValueAsString(v)
def read[T: Manifest](s: String) = readValue(s)
}

}