-
Notifications
You must be signed in to change notification settings - Fork 76
CSV mapper does not support Views or filtering correctly for serialization #93
Comments
Ok, going forward it would be great if you actually created 2 separate github issues for 2 different problems (even if possibly related). Now: the best way to ensure my understanding of the issue would be to add a piece of code to show it. This would allow me to reproduce the problem without misunderstanding what is happening. As to using views when generating schemas: this is an interesting question. I can not say off-hand whether I would expect columns to disappear; esp. since this affects all output formats, not just CSV. |
Ok: Jackson 2.7 will apply Views during schema generation. |
Here is some code attempting to use a filter that will reproduce the issue:
and then a test class to go with it:
if you remove the field unusedFieldBetween then it works so it has to do with fields in the middle. This seems to have popped up somewhere between 2.4.6 and 2.6.3 as this used to work with all classes at 2.4.6 but does not when things are updated to 2.6.3. If you run the test method here you will get the exception: com.fasterxml.jackson.core.JsonGenerationException: Can not skip a field, expecting a value I have a similar problem which I think is related to this. From what I could debug in JsonWriteContext.writeFieldName it sets _gotName to true. It looks like maybe CsvGenerator.writeOmittedField is maybe the culprit here. Let me know if I can help or provide more info. This seems to be a relatively big problem with this version. |
I actually went ahead and took a shot at fixing it. Found the TestFiltering class there and added a method which fails with the old code but works with the new changes in the writeOmittedField method. @cowtowncoder Please take a look and see what you think. I am guessing that this may have been broken by internal changes in the core Jackson code in the last few versions. I am not exactly sure where the error raised in the method would be applicable so some guidance there would help. |
@rob-baily thanks! This should help figuring out what is going on & fix the issue(s). |
@rob-baily Thank you for the fix: I added it in master and 2.6 branch, latter for inclusion in 2.6.5. |
I am using views to serialize objects as well as get a more clean query output. Below is an example of the two JSONs created, one for serialization and the other for query.
The first is a more sanitized view that is given to the user when queried. The second is a view of what is held in memory and used for serialization. But these are views of the same data using serialization views.
Issue 1:
If I create a csv schema using an object mapper set up to use the request view (smaller of the pair) the schema still includes everything from the object. I believe that it should only contain the data configured in the view.
When I try to set up the mapper with this view I keep getting this very vague error: "Can not skip a field, expecting a value."
I traced this in my IDE and see that it is expecting values for fields that have been filtered out (not included) in the view.
I tried to work around this by using filters instead to no avail.
Issue 2:
I set up a filter to mimic the view fro the query data.
I enabled the ignore unknown as well.
csvMapper.enable(JsonGenerator.Feature.IGNORE_UNKNOWN);
This time the issue is that I am not getting any error, but the column names are not properly calling the getter methods. Below is the output I am getting.
sessionNumber,host,venue,scid,channelId,dssId,vcid,ert,scet,sclk,dn,eu,status,dnAlarmState,dnAlarmLevel,euAlarmState,euAlarmLevel,isRealTime
0,somehost,ATLO,76,A-0001,0,0,,,,,,,"Some alarm state",YELLOW,"Some alarm state",NONE,false
As an example, the sclk column should call the "getSclk" method since it has the @JsonProperty("sclk") annotation.
I hope I did something wrong.
The text was updated successfully, but these errors were encountered: