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

Remove override of json creator mode #24

Merged
merged 2 commits into from
Jul 30, 2015
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
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;
}
}
}