Is there a way to modify a POJO field and return the POJO

冷暖自知 提交于 2019-12-11 19:53:40

问题


Is there a way to modify the field of POJO with new property(like using MixIns or @JSONProperty) and get the modified POJO back ? (A way to add/modify field of a POJO dynamically ?)

Like I have a class

 class PojoA<T>{

 private T data;//field to be modified as NewData

 }

So, I tried with MixIns like

    public interface PojoMixIn<T> {
    @JsonProperty("NewData")
     T getData();
     }

Now to get the modified field, I use ObjectMapper

        mapper.addMixInAnnotations(PojoA.class,PojoMixIn.class);
        mapper.writerWithDefaultPrettyPrinter().writeValueAsString(pojoA);

The actual result is a String, but can I be able to get the modified POJO?

来源:https://stackoverflow.com/questions/25364095/is-there-a-way-to-modify-a-pojo-field-and-return-the-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!