-
-
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()
will ignore the configuration SerializationFeature.WRAP_ROOT_VALUE
#4047
Comments
it looks to me like the snippet was incorrectly copied from the |
We'd probably need a more slimmed-down reproduction here. |
@cowtowncoder reproducer: public static void main(String[] args) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
Event value = new Event();
value.id = 1L;
value.name = "foo";
System.out.println(objectMapper.writeValueAsString(value)); // {"event":{"id":1,"name":"foo"}}
System.out.println(objectMapper.valueToTree(value)); // {"id":1,"name":"foo"}
}
@JsonRootName("event")
public static class Event {
public Long id;
public String name;
} The bug was introduced in 2e986df because valueToTree now explicitly drops WRAP_ROOT_VALUE. imo this should be reverted |
Hmmh. Does sounds problematic: wish I had added notes on why I felt this should be disabled. I think there's fundamental friction between |
I will see if we can revert the commit. But until then, anyone can jump on the #4049 refer to. |
By refering to #2989, seems like it. |
#4050 Doesn't break anything 🤔. Was the commit used somewhere? So currently there are two PR's heading to different approach.
|
another alternative is to only revert the change to valueToTree. |
True 👍🏻, as long as it does not introduce another inconsistent behavior. Reading through #2989 tho, it seems like the modification was targeted a broader range (out of databind) to cover formats other than JSON. |
Quick note: I don't think reversal of that sizable commit is the way to go. But I need time to look into alternative approaches. |
Agreed. Closed #4050. Btw, It seems like there might be another issue as pointed in this comment in PR #4049. |
Trying to apply change to |
ObjectMapper.valueToTree()
will ignore the configuration SerializationFeature.WRAP_ROOT_VALUE
Search before asking
Describe the bug
When we upgrade the jackson-databind version, then we found the ObjectMapper.valueToTree will return the different result with the previous version. Actually, we configured the SerializationFeature.WRAP_ROOT_VALUE.
The class is like this:
@JsonRootName("event")
public class Event {
}
The previous ObjectMapper.valueToTree result:
After upgraded the version result:
This should caused by the commit.
2e986df
Can we re-enbale SerializationFeature.WRAP_ROOT_VALUE in ObjectMapper.valueToTree method to keep consistent with method writeValueAsString?
Version Information
2.14.2 (The version after 2.13 should have this issue)
Reproduction
<-- Any of the following
-->
Expected behavior
SerializationFeature.WRAP_ROOT_VALUE configuration should be global and take effect in method valueToTree to keep the same with writeValueAsString
Additional context
No response
The text was updated successfully, but these errors were encountered: