|
| 1 | +package com.fasterxml.jackson.dataformat.yaml.ser; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; |
| 4 | +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; |
| 5 | +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; |
| 6 | + |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +public class GeneratorFeature175Test extends ModuleTestBase { |
| 10 | + /* |
| 11 | + /********************************************************** |
| 12 | + /* Test methods |
| 13 | + /********************************************************** |
| 14 | + */ |
| 15 | + |
| 16 | + // [dataformats-text#175]: arrays indentation with indicator |
| 17 | + public void testArrayWithIndicatorIndentation() throws Exception { |
| 18 | + String yamlBefore = "---\n" + |
| 19 | + "tags:\n" + |
| 20 | + " - tag:\n" + |
| 21 | + " values:\n" + |
| 22 | + " - \"first\"\n" + |
| 23 | + " - \"second\"\n" + |
| 24 | + " name: \"Mathematics\""; |
| 25 | + |
| 26 | + YAMLMapper defaultArrayMapper = YAMLMapper.builder() |
| 27 | + .enable(YAMLGenerator.Feature.INDENT_ARRAYS) |
| 28 | + .build(); |
| 29 | + Map<?, ?> stuff = defaultArrayMapper.readValue(yamlBefore, Map.class); |
| 30 | + String defaultYaml = defaultArrayMapper.writeValueAsString(stuff); |
| 31 | + |
| 32 | + //default array indentation set indicator in separate line |
| 33 | + assertNotSame(yamlBefore, defaultYaml); |
| 34 | + |
| 35 | + YAMLMapper arrayWithIndicatorMapper = YAMLMapper.builder() |
| 36 | + .enable(YAMLGenerator.Feature.INDENT_ARRAYS) |
| 37 | + .enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR) |
| 38 | + .build(); |
| 39 | + |
| 40 | + String arrayWithIndicatorYaml = arrayWithIndicatorMapper.writeValueAsString(stuff); |
| 41 | + assertEquals(yamlBefore, arrayWithIndicatorYaml.trim()); |
| 42 | + |
| 43 | + // and do it again to ensure it is parseable (no need to be identical) |
| 44 | + Map<?, ?> stuff2 = arrayWithIndicatorMapper.readValue(arrayWithIndicatorYaml, Map.class); |
| 45 | + assertNotNull(stuff2); |
| 46 | + assertEquals(stuff, stuff2); |
| 47 | + } |
| 48 | +} |
0 commit comments