-
Notifications
You must be signed in to change notification settings - Fork 76
Impossible to turn off Alphanumeric Sort for bean properties #40
Comments
Property ordering is one thing where I actually wish that I had started with default of alphabetic ordering; and only allowed other stable orderings. Current default is unpredictable because it is based on ordering of This is the background for change, to ensure that all data formats that use index-based encoding (as opposed to name-based, as JSON) -- for now, CSV and Avro -- will use a stable ordering; and alphabetic sorting is the only such default choice. But note that this is just the default ordering: explicit ordering by Having said that, I think it would make sense to allow other methods of defining default ordering; perhaps similar to how one can specify property name strategies for defining name transformations (between Java camel-case and other notations). I am open to suggestions in good, simple, extensive way of doing this. But, before talking about improvements, what is the specific problem you are trying to solve here? |
Thank you for quick response! (CsvMapper) new CsvMapper().disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); Well moving to jackson 2.3.3 caused Junit tests failures because of ordering. Yes I noticed that there is a mapper.typedSchemaFor(JaxBGeneratedFromXML.class) I didn't find a way to generate property ordered schema from POJO without annotations. If there was a way not to be dependent on annotations it would be excellent. The main issue is #26 - some of headers are quoted and some are not (Probably depends on header's name length - moving to recent version could help here :) ). Also need to remove " - double quotes mark at all for CSV generated file and replace line separator with "\r\n" which is implemented in recent version ( #32 and #17 ) . I can close the issue then, because there is a possibility to turn the sorting off |
On #26 package com.fasterxml.jackson.dataformat.csv.impl;
...
public final class CsvWriter
{
...
/**
* Helper method that determines whether given String is likely
* to require quoting; check tries to optimize for speed.
*/
protected final boolean _mayNeedQuotes(String value, int length)
{
// 21-Mar-2014, tatu: If quoting disabled, don't quote
if (_cfgQuoteCharacter < 0) {
return false;
}
// let's not bother checking long Strings, just quote already:
if (length > MAX_QUOTE_CHECK) {
return true;
}
for (int i = 0; i < length; ++i) {
if (value.charAt(i) < _cfgMinSafeChar) {
return true;
}
}
return false;
}
....
} If quoting is enabled and we have long string it will be quoted - certainly a BUG, I think. Cannot do anything with that :( |
No, I don't view that as a bug but feature. Adding quoting is never wrong; choice is more that of aesthetics, or perhaps optimization (to avoid adding quotes). And checking as to whether quoting is needed adds to processing overhead, so you trade speed for more accurate assessment. I am open to improvements here; perhaps a simple |
Back to ordering: it should be simple to add an optional argument for |
|
One suggestion: since handling of quoting is bit different from that of ordering, could we focus on ordering in this issue, and create another issue (or use existing one, there may be one open) for quoting? Especially if it affects quoting of header line; I would like to understand Excel's expectations. |
yes, I think It's a good idea to focus on ordering of properties here and continue with quoting in #26 .
|
I made |
I created #42 for functionality to specify sorting via |
Because of this code AlphanumericSort is set twice. In ObjectMapper
and in CsvMapper
so it's impossible to turn it off. Probably SORT must be applied once or made pluggable.
The text was updated successfully, but these errors were encountered: