zoukankan      html  css  js  c++  java
  • json 转换实体对象

    import javax.servlet.http.HttpServletRequest;

    import com.aliyuncs.utils.StringUtils;
    import com.sinosoft.cms.entity.CoreOrganization;

    import net.sf.json.JSONObject;
    import net.sf.json.JsonConfig;
    import net.sf.json.util.JavaIdentifierTransformer;

    public void coreImport(JSONObject requestJson, HttpServletRequest request) {
    String data = requestJson.getString("data");
    JSONObject jsonObject =JSONObject.fromObject(data);

    //CoreOrganization entInfo = (CoreOrganization)JSONObject.toBean(jsonObject, CoreOrganization.class);//会导致参数不对对象为空
    CoreOrganization entInfo = (CoreOrganization)JSONObject.toBean(jsonObject, getJsonConfig(CoreOrganization.class));

    }

    private JsonConfig getJsonConfig(Class clazz) {
    JsonConfig config = new JsonConfig();
    config.setJavaIdentifierTransformer(new JavaIdentifierTransformer() {

    @Override
    public String transformToJavaIdentifier(String str) {
    if(StringUtils.isEmpty(str)){
    return str;
    }
    return str.substring(0,1).toLowerCase().concat(str.substring(1));
    }
    });
    config.setRootClass(clazz);
    return config;
    }

    qq 891451702
  • 相关阅读:
    分布式session管理解决方案
    RabbitMQ知识汇总
    RabbitMQ之集群模式总结
    Flexbox参数详解
    CSS Lint
    javascript中的defer属性和async属性
    简介BFC
    GIT 牛刀小试 (第二发)
    GIT 牛刀小试 (第一发)
    如何让浏览器支持HTML5标签
  • 原文地址:https://www.cnblogs.com/duoyan/p/15458785.html
Copyright © 2011-2022 走看看