Skip to content
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

null values sent in response json #485

Open
navjeetc opened this issue Jan 8, 2024 · 1 comment
Open

null values sent in response json #485

navjeetc opened this issue Jan 8, 2024 · 1 comment

Comments

@navjeetc
Copy link

navjeetc commented Jan 8, 2024

We have configured our spring boot app to not send null values back in json but we are still getting the null values back. The setup to not send null values using jackson ObjectMapper is in BootstrapConfig like this:

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
..
...
 @Bean
	public ObjectMapper objectMapper() {
		final SimpleDateFormat zuluDateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
		zuluDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
		final ObjectMapper jsonMapper = new ObjectMapper();
		jsonMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
		jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		jsonMapper.registerModule(new JavaTimeModule());
		jsonMapper.setDateFormat(zuluDateFormat);
		jsonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

		return jsonMapper;
	} 

We were earlier using:
implementation 'io.leangen.graphql:spqr:0.12.1'
but after upgrade to 0.12.3 we are getting same results.

When we print the gradle dependencies we do have com.google.code.gson:gson as a dependency of another library.

Is it possible spqr is using gson rather than jackson for object mapping. That seems to be the case as when I convert my entity to json in my EntityMutation class I DO NOT see any null values. And if I convert that json back to an entity and return that entity then the front end does not get null values.

Is there any way to ensure that jackson object mapper is used and not gson or am I missing something else in my setup?

@navjeetc
Copy link
Author

navjeetc commented Jan 8, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant