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
  • 相关阅读:
    Best Cow Fences_二分&&DP
    Palindrome_滚动数组&&DP
    Making the Grade_滚动数组&&dp
    BUY LOW, BUY LOWER_最长下降子序列
    Testing the CATCHER_DP
    Best Sequence_DFS&&KMp
    (Your)((Term)((Project)))
    [SOJ] 畅通工程续
    [SOJ] 商人的宣传
    [SOJ] 无路可逃?
  • 原文地址:https://www.cnblogs.com/duoyan/p/15458785.html
Copyright © 2011-2022 走看看