package cn.seecoder.paas.service.model.converter; import cn.seecoder.paas.data.entity.Config; import cn.seecoder.paas.service.model.vo.ConfigVO; import cn.seecoder.paas.util.ServiceException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.BeanUtils; public class ConfigConverter { public static ConfigVO convertToVO(Config config) throws ServiceException { try { ConfigVO configVO = new ConfigVO(); BeanUtils.copyProperties(config, configVO); ConfigVO.ConfigContent configContent = new ObjectMapper().readValue(config.getContent(), ConfigVO.ConfigContent.class); configVO.setConfig(configContent); return configVO; } catch (JsonProcessingException e) { throw ServiceException.INVALID_DATA; } } public static Config convertToEntity(ConfigVO configVO) throws ServiceException { try { Config config = new Config(); BeanUtils.copyProperties(configVO, config); config.setContent(new ObjectMapper().writeValueAsString(configVO.getConfig())); return config; } catch (JsonProcessingException e) { throw ServiceException.INVALID_DATA; } } }