Set default value for a field while populating POJO using Bean Utils

天涯浪子 提交于 2019-12-02 05:59:20

Try using the org.apache.commons.beanutils.BeanUtilsBean class with aid of the org.apache.commons.beanutils.ConvertUtilsBean class

Basically you could do:

Map<String, String> map = new HashMap<>() {  // new HashMap<String, String> perhaps
    @Override
    public String get(Object key} {
        return super.getOrDefault(key, "john");
    }
}

If you want different defaults per field, use a local map, prefilled with defaults.

Then you should make your own class.

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