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

SortedBy only apply to headers and actual data #96

@ShijunK

Description

@ShijunK

Follow-up to #42

It seems the implementation only sorts the columns in headers, not actual values.

I have a test for 2.6.3

   public void testValueReorderByName() throws Exception
    {
        CsvMapper mapper = mapperForCsv();
        CsvSchema schema = mapper.schemaFor(Mixed.class);
        assertEquals(aposToQuotes("['a','b','c','d']"), schema.getColumnDesc());
        schema = schema.sortedBy("b", "c");
        assertEquals(aposToQuotes("['b','c','a','d']"), schema.getColumnDesc());

        Mixed value = new Mixed();
        value.a = 1;
        value.b = 2;
        value.c = 3;
        value.d = 4;

        schema = schema.withHeader();
        String outputString = mapper.writer(schema).writeValueAsString(Arrays.asList(value));
        assertThat(outputString, is(equalTo("b,c,a,d\n2,3,1,4\n")));

        _verifyLinks(schema);
    }

test output:

java.lang.AssertionError: 
Expected: is "b,c,a,d\n2,3,1,4\n"
     but: was "b,c,a,d\n1,2,3,4\n"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions