java中实体类与map互相转换

java中实体类与map互相转换

pom依赖

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>2.0.6</version>
        </dependency>
HashMap<Object, Object> map = new HashMap<>();
        map.put("ip","123");
        //将map转换为实体类
        User user = JSON.parseObject(JSON.toJSONString(map), User.class);
        //将实体类转换为map
        JSON.parseObject(JSON.toJSONString(user), Map.class);

你可能感兴趣的:(java,json,servlet)