question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Boot Object mapper

See original GitHub issue

Hello,

I there any possibility to share Jackson Object Mapper between Spring Boot and GraphQL?

Instead of duplicating code like this

GraphQL

@Component
public class GraphQlObjectMapperConfigurer implements ObjectMapperConfigurer {
  @Override
  public void configure(ObjectMapper mapper, ObjectMapperConfigurerContext context) {
    mapper.registerModule(new JavaTimeModule())
        .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  }
}

Spring Boot

@Configuration
public class JacksonConfiguration {

  @Bean
  Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
    JavaTimeModule module = new JavaTimeModule();
    return new Jackson2ObjectMapperBuilder()
        .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
        .serializationInclusion(JsonInclude.Include.NON_NULL)
        .findModulesViaServiceLoader(true)
        .modulesToInstall(module);
  }

}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mxabcommented, Jul 22, 2018

I think by default you would expect spring’s default object mapper but I also understand that you may want to configure it differently. Could you add some property like ...graphql.use-default-objectmapper = false and then provide a objectmapper with a certain qualifier?

0reactions
mxabcommented, Aug 25, 2018

Cool!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot: Customize the Jackson ObjectMapper - Baeldung
When using JSON format, Spring Boot will use an ObjectMapper instance to serialize responses and deserialize requests. In this tutorial, we'll take a...
Read more >
Spring Boot - Customize the Jackson ObjectMapper
When using JSON format, Spring Boot will use an ObjectMapper instance to serialize responses and deserialize requests.
Read more >
Configuring ObjectMapper in Spring - java - Stack Overflow
A question: you must name the class JacksonConfiguration ? It's an automagical way to instruct Spring Boot to use this class as configuration ......
Read more >
Jackson ObjectMapper Tutorial - Apps Developer Blog
In this tutorial, you will learn how to use Jackson ObjectMapper with Spring Boot application to serialize and deserialize Java objects.
Read more >
Creating a springboot CRUD api Using the Jackson ... - Medium
Note that in the create method we receive ProductEntity as our RequestBody(JSON) and let the Jackson.ObjectMapper deserializes it into our POJO. now we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found