spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Fix the issue in MappingJackson2MessageConverter where deserializatio…

Open cooperlyt opened this issue 4 months ago • 2 comments

Fix the issue in MappingJackson2MessageConverter where deserialization returns null values for POJOs that do not have @JsonView annotations

When a POJO does not have the JsonView annotation set, and Jackson's DEFAULT_VIEW_INCLUSION is false (the default value in Spring framework #16793), deserialization fails and returns an object with all properties empty.

I added a test in MappingJackson2MessageConverterTests that will fail before I fix it.

	@Test
	public void fromMessageToMessageWithPojoClass(){
		// #16793 https://github.com/spring-projects/spring-framework/issues/16793
		//ObjectMapper objectMapper = JsonMapper.builder().configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false).build();
		MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
		String payload = "{\"string\":\"foo\"}";
		Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
		Object actual = converter.fromMessage(message, MyBean.class, MyBean.class);
		assertThat(actual).isInstanceOf(MyBean.class);
		assertThat(((MyBean) actual).getString()).isEqualTo("foo");
	}

PS: Discussion with jackson-databind issues.

cooperlyt avatar Oct 16 '24 02:10 cooperlyt