Skip to content

ParameterNamesModule does not deserialize with a single parameter constructor when using SnakeCase PropertyNamingStrategy #67

@sonnygill

Description

@sonnygill

Since release 2.9.2, the following test that passes with previous versions is broken.

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

import org.junit.Test;

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

public class JsonCreatorSnakeCaseNamingTest
{
	@Test
	public void shouldDeserializeClassWithJsonCreatorWithSnakeCaseNaming() throws Exception {

		// given
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.registerModule(new ParameterNamesModule());
		objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

		// when
		String json = "{\"first_property\":\"1st\"}";
		ClassWithOneProperty actual = objectMapper.readValue(json, ClassWithOneProperty.class);

		then(actual).isEqualToComparingFieldByField(new ClassWithOneProperty("1st"));
	}

	static class ClassWithOneProperty {
		public final String firstProperty;

		@JsonCreator
		public ClassWithOneProperty(String firstProperty) {
			this.firstProperty = firstProperty;
		}
	}
}

The test passes with if I create the ParameterNamesModule with JsonCreator.Mode.PROPERTIES as the argument.

Is this intended? If so, this should probably be documented as a breaking change. Otherwise existing code bases break without warning.

It appears that the code responsible for this is BasicDeserializerFactory._addExplicitAnyCreator which was newly added in 2.9.2, but I am not certain.

Should I wait for a fix, or switch to using new ParameterNamesModule(JsonCreator.Mode.PROPERTIES)? Can that have any side effects that I should watch out for?

Thanks.

  • Sonny

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions