-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectMapper.valueToTree does not work with @JsonRawValue #348
Comments
Test case:
|
Alas, I don't know if this can be supported: raw values are not portable or inter-operable, and buffering them as such does not necessarily make sense. They are to be used only for injecting exact content in output, using specific output format. This means that Tree Models can't really work too well with them. |
Or, more specifically: while Tree Model could (if we wanted to) support "raw" content as special nodes, it's |
Couldn't the raw value be parsed? At the very least, the javadoc should be updated to note this caveat, as this method is not truly
|
Raw value is just a snippet of output document, in some format (not necessarily JSON), and there is no functionality for partially parsing things. So while it might work, it is not really guaranteed. The idea of trying to parse it is interesting however. Dunno. I would be open to a patch; working for some cases would be improvement over "never works". And yes, I think adding a javadoc note makes sense: I will add that in, regardless. |
+1 |
so what's the preferred method to create unquoted values then? for example, https://github.com/l0rdn1kk0n/wicket-jquery-selectors needs to be able to generate raw values which represent javascript objects, e.g: {
"queryParser" : SomeGlobalObject.someproperty,
"query": "foo"
} With previous (< 2.4) version of jackson-databind, it was possible by using a custom JsonSerializer which simply called {
"queryParser" : "SomeGlobalObject.someproperty",
"query": "foo"
} As it's not possible to call any of the |
There is no supported mechanism for this. But if there really is strong desire to support "raw values" through Tree node representation, a new node type can be added. I am hesitant, however, since I do not want to be promoting use of unquoted values: I think that is wrong usage and should be eliminated, not facilitated. Adding new |
Are there any examples on how one would add a custom |
It's no different than registering serializers/deserializers for any other type. For deserialization it'd be tricky to do in general (would need to override standard I am not quite sure as to your reference on custom
Of these, 1 is more efficient, but 2 is simpler to use. Then again many custom serializers just override handling of dependant pieces without delegation; this may work if you know your exact settings and do not need to delegate to types provided by external datatype modules (like Joda or Guava) |
Hi, As I'd like to use wicket-jquery-selectors with Jackson 2.5, I'm as well trying to ouput raw values using Jackson 2.5 and I haven't made it work so far. Jackson is used by a lot of Java libraries to generate Json used as a configuration for Javascript libraries. At least, it's something very common in the Wicket world. And I'm pretty sure, it's something common in other contexts. Having the ability to output raw values is really something needed in this case, either to reference a Javascript function or a Javascript variable. It would be nice to have a supported way to do so, even if it requires some specific configuration. Is the solution to add a new type really something doable. AFAICS we need to override:
and JsonNodeType is an enum? Would you reconsider implementing the writeRaw* method in TokenBuffer? It looks like the easiest way to perform this and people would still be forced to write custom code to use it so it won't encourage them to do so it not really required. If not, I would appreciate some more guidance on how to be able to do so. And it would be nice to have a nice future-proof way to do it documented in this issue. Thanks for your feedback! |
+1 for supporting at least serialization of raw values |
@gsmet On addition in Could you file a separate issue for adding raw values in If and when raw values may be buffered it'd be easier to solve the other part. |
Done: #737 . |
Due to implementation of #737 and #743 it is now possible to use So, I will consider this implemented to the degree it can be, without forcing conversion to go through actual serialization, which would defeat the purpose of the method as efficient buffered transformation. |
The handy valueToTree shortcut method on ObjectMapper does not appear to support pojos with the @JsonRawValue annotation:
Looking at the TokenBuffer implementation of JsonGenerator used internally for this operation, I find that all the writeRaw methods are unimplemented.
This annotation works as expected in a full round-trip conversion (pojo->JSON->JsonNode). The valueToTree method is described as "Functionally same" so I would expect it to support this annotation (and all others) as well.
The text was updated successfully, but these errors were encountered: