Skip to content

Commit

Permalink
Fix ObjectMapper issues as RestConfiguration bean will conflict with …
Browse files Browse the repository at this point in the history
…engine bean and can't be imported
  • Loading branch information
Tuomo Ala-Vannesluoma committed Aug 21, 2023
1 parent dc714fa commit 1644b29
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package nflow.kotlin

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import io.nflow.engine.config.EngineConfiguration
import io.nflow.engine.config.NFlow
import io.nflow.engine.service.WorkflowInstanceService
import io.nflow.engine.workflow.instance.WorkflowInstanceFactory
import io.nflow.rest.config.NflowRestApiPropertiesConfiguration
import io.nflow.rest.config.RestConfiguration
import io.nflow.rest.config.RestConfiguration.REST_OBJECT_MAPPER
import jakarta.inject.Inject
import jakarta.inject.Named
import nflow.kotlin.workflow.ExampleWorkflow
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.*
import org.springframework.context.event.EventListener;
import javax.inject.Inject

@Import(RestConfiguration::class)
@Import(value = [EngineConfiguration::class, NflowRestApiPropertiesConfiguration::class])
@ComponentScan(value = ["io.nflow.rest"], excludeFilters = [ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = [RestConfiguration::class])])
@Configuration
class WorkflowAppConfig

Expand All @@ -33,6 +41,14 @@ class WorkflowApplication {
.putStateVariable(ExampleWorkflow.VAR_COUNTER, 0)
.build())
}

@Primary
@Bean
@Named(REST_OBJECT_MAPPER)
fun nflowRestObjectMapper(@NFlow nflowObjectMapper: ObjectMapper): ObjectMapper = nflowObjectMapper.copy().apply {
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
}
}

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package io.nflow.springboot.fullstack.gradle;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.nflow.engine.config.EngineConfiguration;
import io.nflow.engine.config.NFlow;
import io.nflow.rest.config.NflowRestApiPropertiesConfiguration;
import io.nflow.rest.config.RestConfiguration;
import jakarta.inject.Inject;

import jakarta.inject.Named;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.context.event.EventListener;

import io.nflow.rest.config.RestConfiguration;
import io.nflow.engine.service.WorkflowInstanceService;
import io.nflow.engine.workflow.instance.WorkflowInstanceFactory;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_TRAILING_TOKENS;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
import static io.nflow.rest.config.RestConfiguration.REST_OBJECT_MAPPER;

@SpringBootApplication
@Import(RestConfiguration.class)
@Import({ EngineConfiguration.class, NflowRestApiPropertiesConfiguration.class })
@ComponentScan(value = "io.nflow.rest", excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = RestConfiguration.class))
public class DemoApplication {

@Inject
Expand All @@ -32,6 +45,16 @@ public void insertWorkflowInstance() {
.build());
}

@Primary
@Bean
@Named(REST_OBJECT_MAPPER)
public ObjectMapper nflowRestObjectMapper(@NFlow ObjectMapper nflowObjectMapper) {
ObjectMapper restObjectMapper = nflowObjectMapper.copy();
restObjectMapper.configure(WRITE_DATES_AS_TIMESTAMPS, false);
restObjectMapper.enable(FAIL_ON_TRAILING_TOKENS);
return restObjectMapper;
}

@Bean
public ExampleWorkflow exampleWorkflow() {
return new ExampleWorkflow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package io.nflow.springboot.fullstack.maven;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.nflow.engine.config.EngineConfiguration;
import io.nflow.engine.config.NFlow;
import io.nflow.rest.config.NflowRestApiPropertiesConfiguration;
import io.nflow.rest.config.RestConfiguration;
import jakarta.inject.Inject;

import jakarta.inject.Named;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.context.event.EventListener;

import io.nflow.rest.config.RestConfiguration;
import io.nflow.engine.service.WorkflowInstanceService;
import io.nflow.engine.workflow.instance.WorkflowInstanceFactory;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_TRAILING_TOKENS;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
import static io.nflow.rest.config.RestConfiguration.REST_OBJECT_MAPPER;

@SpringBootApplication
@Import(RestConfiguration.class)
@Import({ EngineConfiguration.class, NflowRestApiPropertiesConfiguration.class })
@ComponentScan(value = "io.nflow.rest", excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = RestConfiguration.class))
public class DemoApplication {

@Inject
Expand All @@ -32,6 +45,16 @@ public void insertWorkflowInstance() {
.build());
}

@Primary
@Bean
@Named(REST_OBJECT_MAPPER)
public ObjectMapper nflowRestObjectMapper(@NFlow ObjectMapper nflowObjectMapper) {
ObjectMapper restObjectMapper = nflowObjectMapper.copy();
restObjectMapper.configure(WRITE_DATES_AS_TIMESTAMPS, false);
restObjectMapper.enable(FAIL_ON_TRAILING_TOKENS);
return restObjectMapper;
}

@Bean
public ExampleWorkflow exampleWorkflow() {
return new ExampleWorkflow();
Expand Down

0 comments on commit 1644b29

Please sign in to comment.