leangen / graphql-spqr

Build a GraphQL service in seconds
Apache License 2.0
1.09k stars 179 forks source link

null values sent in response json #485

Open navjeetc opened 5 months ago

navjeetc commented 5 months ago

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 commented 5 months ago

Cross posted to Stackoverflow https://stackoverflow.com/questions/77782450/null-values-sent-in-response-json-by-graphql-spqr