Registering an ExclusionStrategy
for deserialization affects serialized output
#2190
Labels
ExclusionStrategy
for deserialization affects serialized output
#2190
Gson version
2.9.1
Java / Android version
Java 17
Description
Registering an
ExclusionStrategy
which excludes a subclass on deserialization affects the serialized output for that class.The underlying issue is the same as for #1833 and #2032.
Maybe at this point there should be a method
TypeAdapter.usesReflection()
whose default implementation returnsfalse
but which can be overridden by subclasses. This would avoid all this special-casing, and it would also allow third-party adapters to make use of this.Important: Fixing this might affect the exclusion handling for serialization, so maybe this cannot be solved easily.
Reproduction steps
When the
ExclusionStrategy
is registered,TypeAdapterRuntimeTypeWrapper
erroneously considers the adapter created byExcluder
(which wraps a reflective adapter) as non-reflective. The assertion above fails because the output is erroneously{"b":{"i":0}}
.The text was updated successfully, but these errors were encountered: