graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Question: How to set my own DateFormat?

Open jacks808 opened this issue 7 years ago • 3 comments

I am want to set my own DateFormat, but I didn't find a way how to set.

ObjectMapperConfigurer is already added.

@Bean
    public ObjectMapperConfigurer buildGraphqlServletObjectMapper() {
        ObjectMapperConfigurer configurer = new ObjectMapperConfigurer() {
            @Override
            public void configure(ObjectMapper mapper) {
                mapper.setDateFormat(new SimpleDateFormat(TimeUtils.DEFAULT_FORMAT));
            }
        };
        return configurer;
    }

But not work. BTW. I am using jackson to parse json.

Help me.

jacks808 avatar Mar 18 '19 09:03 jacks808

Here is the debug result of GraphqlServlet. Use a Map<String, Object> data to create a JSON response. So, my customer object mapper will not parse a not-date-like object use DateFormat.

Evaluate of createResultFromDataAndErrors

jacks808 avatar Mar 18 '19 13:03 jacks808

Finally, I modify data type from java.util.Date to long. And, use getTime() method to put a timestamp value into resolver result.

jacks808 avatar Mar 19 '19 06:03 jacks808

This is not related to this library, but is basic GraphQL. You can use scalars for that, see the following links:

  • https://graphql.org/learn/schema/#scalar-types
  • https://www.graphql-java.com/documentation/v11/scalars/
  • https://github.com/donbeave/graphql-java-datetime

oliemansm avatar Mar 19 '19 08:03 oliemansm