jackson-dataformat-csv parsing complex mapping in header field names

123 Views Asked by At

I'm using the CSV parsing utilities from com.fasterxml.jackson.dataformat.csv. Minimum Java 8.

Let's say I have a POJO as such:

class MyPojo {
    @JsonProperty("Object ID")
    private String objectName;

    // ... other basic fields here

    private Map<String, String> customFields;
    private Map<String, String> mapOfPoints;
}

And a CSV file like this:

Object ID,Point 1,Point 2, Point 3,Point 4,Custom Field 1,Another Custom Field
abc123,1.00;1.00,1.00;-1.00,-1.00;1.00,-1.00;-1.00,something,more of something

Assuming the basic fields that line up to POJO fields with @JsonProperty are parsed fine.

  1. Is it possible to have any data field matching a header that starts with Point to be sent to the mapOfPoints map (I'll parse the actual point data later with something else), where the key is the header name? So the first data row will have a Point 1 key in the mapOfPoints map, with a value of 1.00;1.00.
  2. Further, can I have it so that any field not handled by the JsonProperty annotations and that isn't taken care of by question #1 (so, starting with Point) to go to the customFields map? So in the data row above, there would be a customFields map entry of key Custom Field 1 and value something.
0

There are 0 best solutions below