Skip to content

Commit

Permalink
Fix #115 (actual fix via jackson-databind)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 28, 2019
1 parent a2480bd commit 0ce62fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import java.util.*;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
import com.fasterxml.jackson.dataformat.csv.CsvSchema.Column;

public class SchemaTest extends ModuleTestBase
public class CsvSchemaTest extends ModuleTestBase
{
@JsonPropertyOrder({ "a", "b", "c", "d" })
static class Mixed {
Expand All @@ -31,7 +32,7 @@ static class Point {
@JsonPropertyOrder()
public static class PointWithAnnotation extends Point {}

// for [dataformat-csv#142]
// for [dataformats-text#142]
interface Named {
public String getFirstName();
public String getLastName();
Expand All @@ -41,7 +42,18 @@ static abstract class YZ {
public abstract int getY();
public abstract int getZ();
}


// for [dataformats-text#115]
static class PointWithExplicitIndices115 {
public int z;

@JsonProperty(required = true, value = "y", index = 1)
public int y;

@JsonProperty(required = true, value = "x", index = 2)
public int x;
}

/*
/**********************************************************************
/* Test methods
Expand Down Expand Up @@ -206,4 +218,16 @@ public void testSchemaComposition() throws Exception
assertEquals("lastName", it.next().getName());
assertEquals("x", it.next().getName());
}

// For [dataformat-csv#115]: honor JsonProperty index
public void testSchemaWithExplicitIndices()
{
CsvSchema pointSchema = MAPPER.typedSchemaFor(PointWithExplicitIndices115.class);

assertEquals("y", pointSchema.column(0).getName());
assertEquals("x", pointSchema.column(1).getName());
assertEquals("z", pointSchema.column(2).getName());

_verifyLinks(pointSchema);
}
}
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Modules:
#7: Add `CsvParser.Feature.EMPTY_STRING_AS_NULL` to allow coercing empty Strings
into `null` values
(contributed by Tyler C-R)
#115: JsonProperty index is not honored by CsvSchema builder
-- actually fixed by [databind#2555]

2.10.2 (not yet released)

Expand Down

0 comments on commit 0ce62fb

Please sign in to comment.