Skip to content

Commit 790bc6d

Browse files
authored
fix: Jackson YAML mapper no longer add new lines (#117)
1 parent d57eae1 commit 790bc6d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tzatziki-jackson/src/main/java/com/decathlon/tzatziki/utils/JacksonMapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.databind.SerializationFeature;
99
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
10+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
1011
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
1112
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
1213
import com.google.common.collect.Lists;
@@ -28,7 +29,7 @@ public class JacksonMapper implements MapperDelegate {
2829
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
2930
.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
3031

31-
private static ObjectMapper yaml = configurator.apply(new ObjectMapper(new YAMLFactory()));
32+
private static ObjectMapper yaml = configurator.apply(new ObjectMapper(YAMLFactory.builder().disable(YAMLGenerator.Feature.SPLIT_LINES).build()));
3233
private static ObjectMapper json = configurator.apply(new ObjectMapper());
3334
private static ObjectMapper nonDefaultJson = json.copy()
3435
.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
@@ -113,8 +114,8 @@ private static String toJson(Object object, ObjectMapper objectMapper) throws Js
113114

114115
@SneakyThrows
115116
public String toYaml(Object object) {
116-
if (object instanceof String) {
117-
return (String) object;
117+
if (object instanceof String objectStr) {
118+
return objectStr;
118119
}
119120
return yaml.writeValueAsString(object).replaceAll("^---\n?", "");
120121
}

tzatziki-logback/src/test/resources/com/decathlon/tzatziki/steps/logger.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Feature: to interact with the logger
5656
"""
5757
Then if <level> == INFO => the logs contain:
5858
"""
59-
- ?e .*"message":"some [^ ]+ lines that should be there","logger_name":"com.decathlon.tzatziki.steps.LoggerSteps","thread_name":"main","level":"ERROR".*
59+
- ?e *.*"message":"some [^ ]+ lines that should be there","logger_name":"com.decathlon.tzatziki.steps.LoggerSteps","thread_name":"main","level":"ERROR".*
6060
"""
6161
But if <level> == OFF => the logs are empty
6262

0 commit comments

Comments
 (0)