Order of CSV columns when I make a schema from a Pojo

2,445 views
Skip to first unread message

Benson Margulies

unread,
Jun 26, 2014, 8:09:02 PM6/26/14
to jackso...@googlegroups.com
Exception:

com.fasterxml.jackson.databind.RuntimeJsonMappingException: Can not construct instance of java.lang.Double from String value 'Q5622021': not a valid Double value

Input line:

Q5622021 2008.06.09.sailors.rescued.txt 1 210 220 Steven Guy 0.2762699182535878

Constructor:

   @JsonCreator
    public ResItem(@JsonProperty("entityId") String entityId,
                   @JsonProperty("docId") String docId,
                   @JsonProperty("indocId") String indocId,
                   @JsonProperty("mentionStart") int mentionStart,
                   @JsonProperty("mentionEnd") int mentionEnd,
                   @JsonProperty("mentionText") String mentionText,
                   @JsonProperty("confidence") double confidence) {
        this.entityId = entityId;
        this.docId = docId;
        this.indocId = indocId;
        this.mentionStart = mentionStart;
        this.mentionEnd = mentionEnd;
        this.mentionText = mentionText;
        this.confidence = confidence;
    }

Schema construction:

schema = mapper.schemaFor(ResItem.class).withColumnSeparator('\t');

Iterator constructor:

 MappingIterator<ResItem> iterator = mapper.reader(ResItem.class).with(schema).readValues(inputStream);

What have I done wrong? (2.3.3)

Tatu Saloranta

unread,
Jul 9, 2014, 5:02:40 PM7/9/14
to jackso...@googlegroups.com
Order of properties for CSV module will be (by default) alphabetic ordering, since ordering of getters/setters/fields is basically undefined and unstable (as of JDK 1.7). Although ordering of constructor parameters would be stable source, it is not used.

You may want to just use @JsonPropertyOrder to explicitly define order that input file has.

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tatu Saloranta

unread,
Jul 9, 2014, 5:03:19 PM7/9/14
to jackso...@googlegroups.com
... or, alternatively, explicitly specify ordering for schema; 2.4 has method(s) to feed that in when building CsvSchema object.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages