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

JsonFactory.toJson doesn't work with @JsonProperty #352

Open
id-regis opened this issue Jun 17, 2016 · 1 comment
Open

JsonFactory.toJson doesn't work with @JsonProperty #352

id-regis opened this issue Jun 17, 2016 · 1 comment

Comments

@id-regis
Copy link

id-regis commented Jun 17, 2016

Hi,
Deserialization of beans with @JsonProperty annotation works but for deserialization behavior is very strange.
In the test below serialization ouput from toJson is : {"name":"name","host":"localhost","host":"localhost","name":"name"}

Which is incorrect. Fields are not named according to @JsonProperty and are duplicated, it should be :
{"Name":"name","Address":"localhost"}

Thx

public class Registration {
    @JsonProperty("Name")
    private String name;
    @JsonProperty("Address")
    private String host;
}

public class TestSerializeRegistration {
    @Test
    public void test() {
        Registration registration = new Registration();
        registration.setName("name");
        registration.setHost("localhost");

        ObjectMapper mapper = JsonFactory.create();
        String jsonSource = "{\"Name\":\"name\",\"Address\":\"localhost\"}";
        Registration unserializedRegistration = mapper.fromJson(jsonSource, Registration.class);

        String json = mapper.toJson(unserializedRegistration);
        Assert.assertEquals(json, jsonSource);
    }
}
@RichardHightower
Copy link
Contributor

Couple of things... QBit uses a forked version of Boon.. https://github.com/advantageous/boon I don't think JsonFactory supports annotations by default. You would have to build a JsonMapper that supported it. I will move this issue to https://github.com/advantageous/boon and look at it.

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