teavm-flavour icon indicating copy to clipboard operation
teavm-flavour copied to clipboard

JSON: Cannot override default class information

Open comick opened this issue 6 years ago • 2 comments

When JSON serializer is used to serialize a class that comes as bytecode only is not possible to put annotations on it: defaults from ClassInformation are applied for visibility.

Could having configurable defaults defined in JsonSerializerContext or a user configurable ClassInformationProvider be a reasonable solution?

comick avatar Apr 28 '18 21:04 comick

This is impossible to have configurable defaults since all serializers and deserializers are generated in compile time, and thus all rules applied and resolved during compile time.

You can annotations to the classes by instrumentation. You can use either javaagent + ASM which is standard for JVM, or write a TeaVM plugin and add ClassHolderTransformer from there. Note that when you implement your own plugin (i.e. implement TeaVMPlugin interface), you should apply service loader convention (i.e. META-INF/services).

Another solution would be to add ability to add compiler plugins to Flavour that can customize default rules.

konsoletyper avatar May 04 '18 19:05 konsoletyper

I solved the problem by using a TeaVM plugin on top of https://github.com/konsoletyper/teavm-flavour/pull/17.

comick avatar Feb 03 '19 20:02 comick