I'm trying to register some additional modules to the ObjectMapper used by the Json class. I just want to check if the only way to do this is by directly accessing the ObjectMapper through Json.objectMapper (or Json.prettyMapper). Personally, I find this a little worrisome as practically mutating a static object accessible from anywhere can be pretty dangerous, but if this is the only way, then I guess I have not much choice (other than, of course, using my own ObjectMapper).
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/8354e032-57f7-48c2-8e2e-0edde30f8161%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nope, that's not what I'm suggesting. Pretty much the Json utility is independent from any particular instance of Vert.x instance anyway. I guess I'm just concerned that accessing the ObjectMappers used by the Json class directly through Json.objectMapper is generally seen as bad design.
I guess if I were to implement this, I'd keep Json mostly as is keep the ObjectMappers to itself. Any other client code that would want to register custom modules can just get their own instance of Json.
Json.getInstance().decodeValue(...);
The original Json.decodeValue(...) can be delegated internally for backward compatibility? Something like:
static ... decodeValue(...) {
return getInstance().decodeValue(...);
}
I'm not sure I understand what this adds. If the objection is to statics, then this solves nothing.
I really don't understand what you're suggestion. If Json.getInstance() returns a singleton, and then you configure that, it's going to effect everyone. No different to the current behaviour.
So.. if your code decides to use a custom Json instance, not the default one, how are JsonObject and JsonArray going to know which one to use for encoding/decoding?
Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read or write calls. If configuration of a mapper is modified after first usage, changes may or may not take effect, and configuration calls themselves may fail.
At this point I am completely confused as to what you are suggesting :(How does using a factory prevent you having to specify the mapper when constructing a JsonObject?
On Thursday, June 8, 2017 at 7:08:45 PM UTC+8, Tim Fox wrote:At this point I am completely confused as to what you are suggesting :(How does using a factory prevent you having to specify the mapper when constructing a JsonObject?
Something like:
JsonObjectFactory factory = new JsonObjectFactory(Json.withModule(...));
JsonObject fromString = factory.decode(jsonString);
JsonObject fromMap = factory.create(jsonMap);
Users can pass this factory around the system without having to worry about the ObjectMapper being reconfigured elsewhere.
Well, passing references around everywhere was exactly what I was hoping to avoid :)
It's actually a very common theme - users want to avoid passing things around too much, it's a lot of extra work for them to do that. The current thread on MDC context is one such example of a thread where we're trying to avoid passing things around.I'd be pretty sure that if we instituted this change it would be extremely unpopular, I think most users would rather do:JsonObject obj = new JsonObject();thanJsonObject obj = new JsonObject(someReferenceImGonnaHaveToPassToEveryMethodWhereICreateAJsonObject)
Not to mention this would break almost every Vert.x application to date... ;)
It might be possible mitigate this to some extent using dependency injection. But don't assume most Vert.x users use DI, in my experience it's a minority that do.But maybe I am just "weird" ;)