Skip to content

Adds test that asserts that Static @JsonCreator method does work - refs #229 #230

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
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fasterxml.jackson.module.scala.deser;

public class UserOfValueHolder {

private ValueHolder valueHolder;

public UserOfValueHolder() {
}

public ValueHolder getValueHolder() {
return valueHolder;
}

public void setValueHolder(ValueHolder valueHolder) {
this.valueHolder = valueHolder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.fasterxml.jackson.module.scala.deser;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Objects;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unused import - please remove.



public class ValueHolder {

public final long internalValue;

private ValueHolder(long internalValue) {
this.internalValue = internalValue;
}

@JsonCreator
public static ValueHolder parse(String value) {
return new ValueHolder(Long.parseLong(value));
}

}
17 changes: 17 additions & 0 deletions src/test/scala/com/fasterxml/jackson/module/scala/deser/CreatorTest.scala
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.fasterxml.jackson.module.scala.deser

import java.util.concurrent.TimeUnit

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
Expand Down Expand Up @@ -43,4 +46,18 @@ class CreatorTest extends DeserializationFixture {
val bean = f.readValue[CreatorModeWrapper]("""{"a":"foo"}""")
bean.a.s shouldEqual "foo"
}

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

val regularObjectMapper = new ObjectMapper()

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

// Using objectMapper with DefaultScalaModule
val bean2 = f.readValue[UserOfValueHolder](json)
bean2.getValueHolder.internalValue shouldEqual 2L
}
}