-
Notifications
You must be signed in to change notification settings - Fork 76
JsonPropertyOrder Inconsistencies with Caps #80
Comments
Property order definitely should not cause addition of any properties, so that sounds like a possible bug. |
Hi cowtowncoder, Thanks for looking into this issue. Just to provide more clarity on what I have been trying, please see the following.
Please note that sometimes if the columns are more than they do not follow the order in which they were given in the JsonPropertyOrder Annotation. |
At this point I think I do need a reproducible test case. |
This is related to how Jackson detects fields. If you have public fields the naive bean accessor naming convention does not produce a match between the field and the declared accessor you will get the behavior you are seeing. Couple things:
//Workaround example:
@JsonPropertyOrder({ "DNACount", "RBCCount" })
public static class BloodCount {
public String DNACount;
public String RBCCount;
//Add this to accessor
@JsonProperty("DNACount")
public String getDNACount() {
return this.DNACount;
}
public void setDNACount(String dnaCount) {
this.DNACount = dnaCount;
}
//Add this to accessor
@JsonProperty("RBCCount")
public String getRBCCount() {
return this.RBCCount;
}
public void setRBCCount(String rbcCount) {
this.RBCCount = rbcCount;
}
} |
There is another issue with regard to capitalization that happens regardless of the public or private status of the field. Fields with a single character acronyms are duplicated since Jackson fails to match the eTradeId field against getETradeId() method. Note that the eTradeId field is duplicated in the output with the etradeId as the header name: @JsonPropertyOrder({ "E-Trade ID", "MY-Trade ID" })
public static class EtradeAccount {
@JsonProperty("E-Trade ID")
private final String eTradeId;
@JsonProperty("MY-Trade ID")
private final String myTradeId;
@JsonCreator
public EtradeAccount(String eTradeId, String myTradeId) {
super();
this.eTradeId = eTradeId;
this.myTradeId = myTradeId;
}
public String getETradeId() {
return this.eTradeId;
}
public String getMyTradeId() {
return this.myTradeId;
}
}
@Test
public void jacksonCsvCapTest() throws IOException {
final CsvMapper csvMapper = new CsvMapper();
final EtradeAccount etradeAccount = new EtradeAccount("eTradeIdValue", "myTradeValue");
final EtradeAccount[] etradeAccounts = { etradeAccount };
try (StringWriter writer = new StringWriter()) {
csvMapper.writer(csvMapper.schemaFor(EtradeAccount.class)
.withHeader())
.writeValues(writer)
.writeAll(etradeAccounts);
final String etradeAccountCSV = writer.toString();
/*
* Returns:
* "E-Trade ID","MY-Trade ID",etradeId
* eTradeIdValue,myTradeValue,eTradeIdValue
*/
System.out.println(etradeAccountCSV);
}
} |
One related feature is Note, too, that In your example, problem comes from the fact that no getter/setter name can ever imply property name of "eTradeId"; there is no convention that produces this. If such a name is needed, additional An alternative would be registering custom |
At this point I don't see a problem that is specific to CSV module. It is possible that there is a naming issue with standard Alternatively it could be that issue #96 was at work here; if so, I fixed that for 2.6.5 / 2.7.0. |
Saw some strange behavior of CSVMapper with JsonPropertOrder Annotation while beginning the attribute names with Caps. In below example if I try to build the schema directly from the Example Class then I get 4 Columns instead of 2. It takes "dnacode" & "rbccount" in addition to the given two columns.
Am I doing anything wrong or is this a tiny bug?
The text was updated successfully, but these errors were encountered: