Skip to content

Attempt to fix JsonCreator related bugs. #236

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

Merged
merged 2 commits into from
Mar 1, 2016
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
14 changes: 7 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ scalacOptions += "-target:jvm-1.6"

libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.4",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.4",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.4",
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.4",
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.5",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.5",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.5",
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.5",
// test dependencies
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.4" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.4" % "test",
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.4" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.5" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.5" % "test",
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.5" % "test",
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
"junit" % "junit" % "4.11" % "test"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector
}
}

override def findCreatorBinding(a: Annotated): JsonCreator.Mode =
if (isScala(a) && hasCreatorAnnotation(a)) JsonCreator.Mode.PROPERTIES else null

override def findCreatorBinding(a: Annotated): JsonCreator.Mode = {
val ann = _findAnnotation(a, classOf[JsonCreator])
if (ann != null) {
ann.mode()
} else if (isScala(a) && hasCreatorAnnotation(a)) {
JsonCreator.Mode.PROPERTIES
} else null
}
}

trait ScalaAnnotationIntrospectorModule extends JacksonModule {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;

public class ValueHolder {

public final long internalValue;

private ValueHolder(long internalValue) {
Expand All @@ -14,5 +13,4 @@ private ValueHolder(long internalValue) {
public static ValueHolder parse(String value) {
return new ValueHolder(Long.parseLong(value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ class CreatorTest extends DeserializationFixture {
}

it should "work with static method creator" in { f =>
val json = """{"valueHolder": "2"}"""
val json = "\"2\""

val regularObjectMapper = new ObjectMapper()

// Using regular objectMapper
val bean1 = regularObjectMapper.readValue(json, classOf[UserOfValueHolder])
bean1.getValueHolder.internalValue shouldEqual 2L
val v1 = regularObjectMapper.readValue(json, classOf[ValueHolder])
v1.internalValue shouldEqual 2L

// Using objectMapper with DefaultScalaModule
val bean2 = f.readValue[UserOfValueHolder](json)
bean2.getValueHolder.internalValue shouldEqual 2L
val v2 = f.readValue[ValueHolder](json)
v2.internalValue shouldEqual 2L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ class CaseClassSerializerTest extends SerializerTest {
}

it should "serialize a case class with unicode name properties" in {
serialize(UnicodeNameCaseClass(23, "the name of this")) should equal( """{"name":"the name of this","winning-id":23}""")
serialize(UnicodeNameCaseClass(23, "the name of this")) should (
equal( """{"name":"the name of this","winning-id":23}""") or
equal( """{"winning-id":23,"name":"the name of this"}""")
)
}

it should "seralize a generic case class" in {
Expand Down