boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

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

Open id-regis opened 8 years ago

id-regis commented 8 years ago

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 commented 8 years ago

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.