Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 84407c9

Browse files
committed
Implement #11: default to alphabetic sorting of properties
1 parent 23e74fb commit 84407c9

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Project: jackson-dataformat-csv
22
Version: 2.3.0 (xx-xxx-2013)
33

4+
#11: Default `CsvMapper` to use alphabetic sorting of properties (since
5+
alternative is basically undefined; and with JDK 1.7+, unstable too)
46
- Add support for `JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN`
57

68
------------------------------------------------------------------------

src/main/java/com/fasterxml/jackson/dataformat/csv/CsvMapper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
66
import com.fasterxml.jackson.databind.util.NameTransformer;
77
import com.fasterxml.jackson.core.type.TypeReference;
8-
98
import com.fasterxml.jackson.dataformat.csv.impl.LRUMap;
109

1110
/**
@@ -42,6 +41,8 @@ public CsvMapper()
4241
public CsvMapper(CsvFactory f)
4342
{
4443
super(f);
44+
// As per #11: default to alphabetic ordering
45+
enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
4546
}
4647

4748
/*

src/test/java/com/fasterxml/jackson/dataformat/csv/TestUnwrappingWithCSV.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public Location(int x, int y) {
2020
}
2121
}
2222

23+
// IMPORTANT: ordering DOES matter here
24+
@JsonPropertyOrder({ "name", "location" })
2325
static class Unwrapping {
2426
public String name;
2527
@JsonUnwrapped(prefix="loc.")

src/test/java/com/fasterxml/jackson/dataformat/csv/TestVersions.java

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.*;
44

55
import com.fasterxml.jackson.core.*;
6+
import com.fasterxml.jackson.databind.MapperFeature;
67

78
public class TestVersions extends ModuleTestBase
89
{
@@ -18,6 +19,13 @@ public void testMapperVersions() throws IOException
1819
jgen.close();
1920
}
2021

22+
// Mostly to verify #11
23+
public void testMapperDefaults()
24+
{
25+
CsvMapper mapper = new CsvMapper();
26+
assertTrue(mapper.isEnabled(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY));
27+
}
28+
2129
/*
2230
/**********************************************************
2331
/* Helper methods

0 commit comments

Comments
 (0)