Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #24 from lpandzic/remove-override-of-json-creator-…
Browse files Browse the repository at this point in the history
…mode

Remove override of json creator mode
  • Loading branch information
cowtowncoder committed Jul 30, 2015
2 parents 6919787 + f06596a commit bd54601
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public String findImplicitPropertyName(AnnotatedMember m) {
@Override
public JsonCreator.Mode findCreatorBinding(Annotated a) {

JsonCreator ann = a.getAnnotation(JsonCreator.class);
if (ann != null) {
return ann.mode();
}

return creatorBinding;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.fasterxml.jackson.module.paramnames;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.BDDAssertions.then;

public class DelegatingCreatorTest {

@Test
public void shouldNotOverrideJsonCreatorAnnotationWithSpecifiedMode() throws IOException {

// given
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));

// when
ClassWithDelegatingCreator actual = objectMapper.readValue("{\"value\":\"aValue\"}", ClassWithDelegatingCreator.class);

// then
Map<String, String> props = new HashMap<>();
props.put("value", "aValue");
ClassWithDelegatingCreator expected = new ClassWithDelegatingCreator(props);
then(actual).isEqualToComparingFieldByField(expected);
}

static class ClassWithDelegatingCreator {

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
ClassWithDelegatingCreator(Map<String, String> props) {
this.value = props.get("value");
}

String getValue() {
return value;
}
}
}

0 comments on commit bd54601

Please sign in to comment.