- All Implemented Interfaces:
- Pass
public class GsonOptimizer
extends java.lang.Object
implements Pass
This pass is the entry point for the GSON optimizations.
The optimization roughly performs the following steps:
- Find all usages of GSON in the program code: calls to toJson() or fromJson().
- Derive the domain classes that are involved in the GSON call, either
directly (passed as argument to GSON) or indirectly (a field or element
type of another domain class).
- Inject optimized methods into the domain classes that serialize and
deserialize the fields of the domain class without relying on reflection.
- Inject and register GSON type adapters that utilize the optimized
serialization and deserialization methods on the domain classes and bypass
the reflective GSON implementation.
As an additional protection measure, the JSON field names are assigned to
a field index. The mapping between field indices and field names is done
from the classes _OptimizedJsonReaderImpl and _OptimizedJsonWriterImpl, which
have String encryption applied to them. This allows injecting serialization
and deserialization code into the domain classes that have no JSON field
names stored in them as plain text.