Hey all. I have an endpoint that's unstable (data ...
# serialization
s
Hey all. I have an endpoint that's unstable (data models are changing semi-frequently without a versioning system- it's an ongoing discussion) for an application I am working on. I am using a
Json(context = serializationContext)
where my
serializationContext
is a
SerializersModule
which contains all of my contextual serializer mappings, to stringify/parse values, but need it to able to adapt to situations where the data model has changed server-side for older app versions that don't have an updated model. I could use
Json.nonstrict
for parsing/writing, but is there any way to use it with my
serializationContext
and have it fall back to
nonstrict
if the models don't match? Or is there a better way to do this that I'm missing?
I mainly just want it so that if it encounters an additional field it will fall back to
nonstrict
, but if a field is missing it will still crash during testing. I could catch the
JsonDecodingException
and fall back to non-strict that way, but I am hoping there is a better solution 😨
m
Maybe you could pass the Json configuration as a parameter? Then you could pass a strict config in tests and a non-strict one in production.
s
Not a bad solution; I could set the json config based off of the build environment I suppose. Thanks for the suggestion!