Skip to content
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.writerWithType has no effect in 2.3.0 #412

Closed
jhalterman opened this issue Feb 20, 2014 · 3 comments
Closed

ObjectMapper.writerWithType has no effect in 2.3.0 #412

jhalterman opened this issue Feb 20, 2014 · 3 comments

Comments

@jhalterman
Copy link

I'm using ObjectMapper.writerWithType on an ObjectMapper that has SerializationFeature.WRAP_ROOT_VALUE enabled to override the rootType when writing a value as a string. Specifically I'm doing this to ensure that proxied types have their parent class name written instead of the proxy class name.

This worked fine with 2.1.1. Did something change?

@cowtowncoder
Copy link
Member

It sounds like this could well be a be a bug. But I am not sure I follow the exact problem, so it would be great if you could come up with a simple unit test. And hopefully fix the problem.

@jhalterman
Copy link
Author

Sure - Here's a simple failing test:


public static class TestCommandParent {
    public String uuid;
    public int type;
 }

 public static class TestCommandChild extends TestCommandParent {
 }

public void test() {
    TestCommandChild cmd = new TestCommandChild();
    cmd.uuid = "1234";
    cmd.type = 1;

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
    ObjectWriter writer = mapper.writerWithType(TestCommandParent.class);
    String result =  writer.writeValueAsString(cmd);

    assertEquals("{\"TestCommandParent\":{\"uuid\":\"1234\",\"type\":1}}", result);
}

The actual result is {"TestCommandChild":{"uuid":"1234","type":1}}

cowtowncoder added a commit that referenced this issue Feb 26, 2014
cowtowncoder added a commit that referenced this issue Feb 26, 2014
@cowtowncoder cowtowncoder added this to the 2.2 milestone Feb 26, 2014
cowtowncoder added a commit that referenced this issue Feb 26, 2014
@cowtowncoder cowtowncoder modified the milestones: 2/, 2.2 Feb 26, 2014
@cowtowncoder
Copy link
Member

Fixed; was simply not using root type for locating root name to use. Will be in 2.3.2 (and 2.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants