This commit is contained in:
2025-10-21 16:40:10 +02:00
parent 5753c82384
commit 2b6ef3ab14
19 changed files with 1020 additions and 28 deletions

View File

@@ -1,24 +1,27 @@
package zw.qantra.tm.configs;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
@Configuration
@Service
public class JacksonConfig {
@Bean
@Primary
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new JodaModule());
objectMapper.registerModule(new Jdk8Module());
@Autowired
private ObjectMapper nflowObjectMapper;
return objectMapper;
@EventListener(ApplicationReadyEvent.class)
public void updateMapper() {
// It's crucial to create a new ObjectMapper instance here
// instead of modifying an autowired one.
nflowObjectMapper.registerModule(new JavaTimeModule());
nflowObjectMapper.registerModule(new JodaModule());
nflowObjectMapper.registerModule(new Jdk8Module());
nflowObjectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
}

View File

@@ -0,0 +1,79 @@
package zw.qantra.tm.configs;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import io.nflow.engine.config.EngineConfiguration;
import io.nflow.engine.config.NFlow;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.util.List;
@Configuration
public class NflowConfiguration {
/**
* Creates the primary, application-wide ObjectMapper.
* <p>
* This bean is marked as {@code @Primary} to ensure it's the default for dependency injection
* throughout the application. It's configured using Spring Boot's {@link Jackson2ObjectMapperBuilder},
* which automatically registers modules for Java 8 Time, Optional, etc., if they are on the classpath.
* It also includes any custom {@link Module} beans defined in the application context.
* </p>
*
* @param builder The default Jackson2ObjectMapperBuilder, pre-configured by Spring Boot.
* @param customModules A list of all custom Jackson {@link Module} beans found in the application context.
* @return A customized {@link com.fasterxml.jackson.databind.ObjectMapper}.
*/
@Primary
@Bean
public ObjectMapper primaryObjectMapper(Jackson2ObjectMapperBuilder builder, List<Module> customModules) {
builder.modules(customModules);
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return builder.build();
}
/**
* Overrides the default ObjectMapper used by the nFlow REST API.
* <p>
* This bean definition ensures that the nFlow REST endpoints use the same consistent,
* primary ObjectMapper as the rest of the application.
* </p>
*/
@Bean("nflowRestObjectMapper")
public ObjectMapper nflowRestObjectMapper(ObjectMapper primaryObjectMapper) {
return primaryObjectMapper;
}
/**
* Overrides the default ObjectMapper used by the nFlow Engine for variable serialization.
* <p>
* This is the key fix for `InvalidDefinitionException` with `LocalDateTime` in workflow variables.
* It ensures the engine uses our fully configured primary ObjectMapper.
* </p>
*/
@Bean("nflowEngineObjectMapper")
public ObjectMapper nflowEngineObjectMapper(ObjectMapper primaryObjectMapper) {
return primaryObjectMapper;
}
@Bean
@NFlow
public EngineConfiguration.EngineObjectMapperSupplier nflowObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.registerModule(new JodaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JSR310Module());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return () -> mapper;
}
}

View File

@@ -29,6 +29,7 @@ public class SecurityConfig {
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/configs/seed/**").permitAll()
.requestMatchers("/test/**").permitAll()
.requestMatchers("/explorer/**").permitAll()
.requestMatchers("/nflow/**").permitAll()