Skip to content

Commit 7c32639

Browse files
committed
Merge pull request #236 from nbauernfeind/JsonCreator2.6
Attempt to fix JsonCreator related bugs.
2 parents 8aab725 + 8af5236 commit 7c32639

File tree

6 files changed

+24
-35
lines changed

6 files changed

+24
-35
lines changed

build.sbt

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ scalacOptions += "-target:jvm-1.6"
2727

2828
libraryDependencies ++= Seq(
2929
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
30-
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.4",
31-
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.4",
32-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.4",
33-
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.4",
30+
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.5",
31+
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.5",
32+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.5",
33+
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.5",
3434
// test dependencies
35-
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.4" % "test",
36-
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.4" % "test",
37-
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.4" % "test",
35+
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.5" % "test",
36+
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.5" % "test",
37+
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.5" % "test",
3838
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
3939
"junit" % "junit" % "4.11" % "test"
4040
)

src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector
9191
}
9292
}
9393

94-
override def findCreatorBinding(a: Annotated): JsonCreator.Mode =
95-
if (isScala(a) && hasCreatorAnnotation(a)) JsonCreator.Mode.PROPERTIES else null
96-
94+
override def findCreatorBinding(a: Annotated): JsonCreator.Mode = {
95+
val ann = _findAnnotation(a, classOf[JsonCreator])
96+
if (ann != null) {
97+
ann.mode()
98+
} else if (isScala(a) && hasCreatorAnnotation(a)) {
99+
JsonCreator.Mode.PROPERTIES
100+
} else null
101+
}
97102
}
98103

99104
trait ScalaAnnotationIntrospectorModule extends JacksonModule {

src/test/java/com/fasterxml/jackson/module/scala/deser/UserOfValueHolder.java

-17
This file was deleted.

src/test/java/com/fasterxml/jackson/module/scala/deser/ValueHolder.java

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.annotation.JsonCreator;
44

55
public class ValueHolder {
6-
76
public final long internalValue;
87

98
private ValueHolder(long internalValue) {
@@ -14,5 +13,4 @@ private ValueHolder(long internalValue) {
1413
public static ValueHolder parse(String value) {
1514
return new ValueHolder(Long.parseLong(value));
1615
}
17-
1816
}

src/test/scala/com/fasterxml/jackson/module/scala/deser/CreatorTest.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ class CreatorTest extends DeserializationFixture {
4848
}
4949

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

5353
val regularObjectMapper = new ObjectMapper()
5454

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

5959
// Using objectMapper with DefaultScalaModule
60-
val bean2 = f.readValue[UserOfValueHolder](json)
61-
bean2.getValueHolder.internalValue shouldEqual 2L
60+
val v2 = f.readValue[ValueHolder](json)
61+
v2.internalValue shouldEqual 2L
6262
}
6363
}

src/test/scala/com/fasterxml/jackson/module/scala/ser/CaseClassSerializerTest.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ class CaseClassSerializerTest extends SerializerTest {
106106
}
107107

108108
it should "serialize a case class with unicode name properties" in {
109-
serialize(UnicodeNameCaseClass(23, "the name of this")) should equal( """{"name":"the name of this","winning-id":23}""")
109+
serialize(UnicodeNameCaseClass(23, "the name of this")) should (
110+
equal( """{"name":"the name of this","winning-id":23}""") or
111+
equal( """{"winning-id":23,"name":"the name of this"}""")
112+
)
110113
}
111114

112115
it should "seralize a generic case class" in {

0 commit comments

Comments
 (0)