Closed ufoscout closed 6 years ago
Looking into it.
@ufoscout I've tried to reproduce it in Java and in Kotlin but failed. Can you provide a reproducer?
@cescoffier After some investigations, I found that the issue happens only when the default Json.mapper is set to the Jackson mapper for Kotlin. E.g., this causes the bug:
Json.mapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
Json.prettyMapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
At this point I am not sure what/where is the issue since the mapper works fine everywhere else.
@ufoscout would you mind try this on your mappers:
// custom types
module.addSerializer(JsonObject.class, new JsonObjectSerializer());
module.addSerializer(JsonArray.class, new JsonArraySerializer());
// he have 2 extensions: RFC-7493
module.addSerializer(Instant.class, new InstantSerializer());
module.addSerializer(byte[].class, new ByteArraySerializer());
and see if that fixes the problem ?
@vietj Yes, indeed adding those serializers fixes the issue. However, they are declared as private into the Json class, so there is no way to reuse them. Nevertheless, I found a better solution. In fact, instead of overriding the Json mappers, I can extend them by adding the KotlinModule:
Json.mapper.registerModule(KotlinModule())
Json.prettyMapper.registerModule(KotlinModule())
This is more maintainable and works as expected. Probably this should be reported somewhere in the kotlin support documentation.
@ufoscout thanks for reporting, I think actually we will add documentation in vertx-core as this is a not only kotlin issue.
@vietj Why do you have a custom serializer for the Instant class? Shouldn't you instead register the JavaTimeModule provided by Jackson?
@ufoscout I think @pmlopes can elaborate on it
Closing this issue, not related to vert.x config.
In my project I have two config files (one for application configuration and the other for tests):
config.json:
test-config.json:
They are loaded this way (kotlin code):
If I do not add the testFileStore to the ConfigRetrieverOptions(), everything works fine and the generated JsonObject is:
But, when I add the testFileStore then the JsonObject is wrong:
Please note that the error can be reproduced by simply adding two times the same file. For example this code:
generates this wrong JsonObject: