Improving serialization layer for JS applications #730
-
Hi everyone. I extracted java-js converters I'm using for serialization-deserialization into separate project https://github.com/ihromant/teavm-io . private final ObjectMapper map = JsonMapper.builder()
.serializationInclusion(JsonInclude.Include.NON_NULL)
.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX)
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.build(); For now it's enough for my needs. But I'm thinking about the future. So, the questions are the following
private final Converters map = Converters.builder()
.serializationInclusion(JsonInclude.Include.NON_NULL)
.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX)
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.build(); and then use it wherever I need. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
As for pt.2, you could have used Gradle, with it this is more convenient. However, since you have a Maven-based build, you should pass additional system properties manually. Please, refer to documentation for specific Maven plugin, e.g. maven-surefire-plugin, to learn how to do that. You can find list of system properties here. |
Beta Was this translation helpful? Give feedback.
-
As for pt.1, I don't fully understand the issue here. Consider you want to configure whether enums are written by index or by name. Then you declare abstraction like BTW, in my proprietary JSON serializer/deserializer, I don't ever use this Jackson-based approach and configure everything explicitly. I find the way provided by Jackson a bit confusing: when you see at JSON and try to understand why it was generated this way (or rather, why given JSON is not properly parsed), looking on annotations is not enough and you should also find out where particular configuration is created. One suggestion to Converters API: please, open |
Beta Was this translation helpful? Give feedback.
-
As for pt.3, please, provide instructions to reproduce. I could not. You can avoid making your project structure flat by introducing another module that contains all code generation stuff. Add this module to |
Beta Was this translation helpful? Give feedback.
-
Ah, I managed to reproduce 'strange errors'. You should mark all your code generation related classes with |
Beta Was this translation helpful? Give feedback.
As for pt.1, I don't fully understand the issue here. Consider you want to configure whether enums are written by index or by name. Then you declare abstraction like
EnumSerializer
interface, provide implementations for name- and index-based approaches and declareenumSerializer
field inConverters
. Then, rewrite your serializer generating code to take this field upon constructions of a serializer of class, containing enum. Sure, this would make generated JS grow. If you want avoid latter, then you can configure at compile-time. You can use any kind of configuration you want, for example, based onServiceLoader
, or read TeaVM properties from plugin.BTW, in my proprietary JSON serializer/…