-
Notifications
You must be signed in to change notification settings - Fork 76
CSV mapper does not support Views or filtering correctly for serialization #93
Description
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.
{
"venue" : "ATLO",
"sessionNumber" : 0,
"scid" : 76,
"dssId" : 0,
"vcid" : 0,
"host" : "somehost",
"isRealTime" : false,
"channelId" : "A-0001",
"dnAlarmState" : "Some alarm state",
"euAlarmState" : "Some alarm state",
"dnAlarmLevel" : "YELLOW",
"euAlarmLevel" : "NONE",
"status" : "",
"dn" : 1444088455219,
"eu" : 1.444088455219E12,
"sclk" : "1444088455.00334",
"ert" : "1970-017T17:08:08.4550002",
"scet" : "1970-017T17:08:08.455"
}
{
"@class" : "jpl.gds.core.globallad.data.EhaGlobalLadData",
"eventTime" : 1444088455219,
"sclkCoarse" : 1444088455,
"sclkFine" : 219,
"ertMilliseconds" : 1444088455,
"ertNanoseconds" : 219,
"scetMilliseconds" : 1444088455,
"scetNanoseconds" : 219,
"venue" : "ATLO",
"sessionNumber" : 0,
"scid" : 76,
"dssId" : 0,
"vcid" : 0,
"host" : "somehost",
"insertNumber" : 1,
"isRealTime" : false,
"isHeader" : false,
"isMonitor" : false,
"isSse" : false,
"isFsw" : true,
"channelId" : "A-0001",
"dnType" : 0,
"dnAlarmState" : "Some alarm state",
"euAlarmState" : "Some alarm state",
"dnAlarmLevel" : "YELLOW",
"euAlarmLevel" : "NONE",
"dnRaw" : "AAABUDphIDM=",
"euRaw" : "QnUDphIDMAA=",
"status" : ""
}
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."
com.fasterxml.jackson.core.JsonGenerationException: Can not skip a field, expecting a value
at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1574)
at com.fasterxml.jackson.dataformat.csv.CsvGenerator.writeOmittedField(CsvGenerator.java:759)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsOmittedField(BeanPropertyWriter.java:592)
at com.fasterxml.jackson.databind.ser.impl.FilteredBeanPropertyWriter$SingleView.serializeAsField(FilteredBeanPropertyWriter.java:66)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:552)
at com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer.serialize(TypeWrappedSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1052)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:923)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
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.
List<String> csvColumns = Arrays.asList("sessionNumber", "host", "venue", "scid", "channelId", "dssId", "vcid", "ert", "scet", "sclk", "dn", "eu", "status", "dnAlarmState", "dnAlarmLevel", "euAlarmState", "euAlarmLevel", "isRealTime");
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.