You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now inside the report classes, I have some time fields, which I want to serialize differently, so I've made a custom serializer class
publicstaticclassTimeFieldSerializerimplementsJsonSerializer<TimeField> {
privateTimeZonem_timeZone;
publicTimeFieldSerializer(finalTimeZonetimeZone) {
m_timeZone = timeZone;
}
@Overridepublicvoidserialize(finalTimeFieldvalue, finalJsonGeneratorgen, finalSerializerProviderserializers)
throwsIOException {
if (value.getTime() == null) {
// dont include it
} else {
finalStringtimestamp = Nanos.toString(value.getTime(), timeZone);
gen.writeString(timestamp);
}
}
}
The issue is that when I don't write any value in the custom serializer, i get a JsonGeneratorException: Can not write a field name, expecting a value. But when I write null, it shows up as null in the Json Output. How do I get it to not serialize it at all. I think the issue is the level I'm doing the serialization at. I should be doing the serialization at the class level, but the issue is that when serializing I need to pass it the timezone variable, so the only way to do that is to add it as a module. Is there a solution to this, or is this a limitation in the library?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi so I have the following classes
Now inside the report classes, I have some time fields, which I want to serialize differently, so I've made a custom serializer class
The issue is that when I don't write any value in the custom serializer, i get a
JsonGeneratorException: Can not write a field name, expecting a value
. But when I write null, it shows up as null in the Json Output. How do I get it to not serialize it at all. I think the issue is the level I'm doing the serialization at. I should be doing the serialization at the class level, but the issue is that when serializing I need to pass it the timezone variable, so the only way to do that is to add it as a module. Is there a solution to this, or is this a limitation in the library?Beta Was this translation helpful? Give feedback.
All reactions