Commit 94e18a23 by s_guodong

从容器中获取ObjectMapper

parent 00cce7ce
......@@ -2,6 +2,7 @@ package com.ceb.gjjs.mda.config;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
......@@ -30,6 +31,7 @@ public class JsonConfig {
// 反序列化的时候如果多了其他属性,不抛出异常
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// 日期格式处理
// objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
......
......@@ -7,7 +7,6 @@ import com.brilliance.mda.runtime.mda.driver.MdaEnv;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.impl.AttributeValue;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import oracle.sql.TIMESTAMP;
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
......@@ -23,6 +22,8 @@ import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import java.io.*;
import java.math.BigDecimal;
......@@ -58,12 +59,26 @@ public class MdaUtils {
pMap.clear();
}
private static synchronized Properties getProperties(String name)
throws FileNotFoundException, IOException {
Properties properties = (Properties) pMap.get(name);
private static synchronized Properties getProperties(String name) throws IOException {
Properties properties = pMap.get(name);
if (properties == null) {
properties = new Properties();
properties.load(new FileInputStream(new File(name)));
//路径问题: 不存在就去类路径下找
File propfile = new File(name);
if (!propfile.exists()) {
String pathToUse = StringUtils.cleanPath(name);
IContext ctx = MdaEnv.getContext();
String rootpath = ctx.getEnvConfig().getRootPath();
pathToUse = pathToUse.substring(rootpath.length());
if (pathToUse.startsWith("/")) {
pathToUse = pathToUse.substring(1);
}
ClassLoader classLoader = ClassUtils.getDefaultClassLoader();
InputStream in = classLoader.getResourceAsStream(pathToUse);
properties.load(in);
} else {
properties.load(new FileInputStream(propfile));
}
pMap.put(name, properties);
}
return properties;
......@@ -589,7 +604,8 @@ public class MdaUtils {
return Collections.EMPTY_LIST;
}
public static final void saveLines(List<String> lines, String lineEnding, String fileName, String encoding) {
public static final void saveLines(List<String> lines, String lineEnding, String fileName, String
encoding) {
try {
IOUtils.writeLines(lines, "", new FileOutputStream(fileName), encoding);
} catch (Exception e) {
......@@ -654,7 +670,8 @@ public class MdaUtils {
return sheetNames;
}
public static final int loadExcel(List<String[]> list, IStream s, int sheetIndex, int rowOffset, int rowMax, int columnOffset, int columnCount) {
public static final int loadExcel(List<String[]> list, IStream s, int sheetIndex, int rowOffset,
int rowMax, int columnOffset, int columnCount) {
Workbook wb = getWorkbook(s);
if (wb == null)
return -1;
......@@ -765,7 +782,8 @@ public class MdaUtils {
unloadExcel(new List[]{list}, new String[1], s, flag);
}
public static final void generate(String templateFileName, String fileName, String exportType, Map params, Object data) {
public static final void generate(String templateFileName, String fileName, String exportType, Map
params, Object data) {
// FileOutputStream fos = null;
// try {
// fos = new FileOutputStream(fileName);
......@@ -777,7 +795,8 @@ public class MdaUtils {
// }
}
public static final void generate(String templateFileName, IStream is, String exportType, Map params, Object data) {
public static final void generate(String templateFileName, IStream is, String exportType, Map
params, Object data) {
// try {
// ReportUtils.generate(templateFileName, is.getOutputStream(), exportType, params, data);
// } catch (Exception e) {
......@@ -928,9 +947,8 @@ public class MdaUtils {
}
public static void saveData(IModule module, IStream os) {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = MdaEnv.getBean(ObjectMapper.class);
try {
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.writeValue(os.getOutputStream(), module);
} catch (Exception e) {
log.error("模型序列化异常", e);
......@@ -952,7 +970,7 @@ public class MdaUtils {
}
public static void loadData(IModule module, IStream stream) {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = MdaEnv.getBean(ObjectMapper.class);
try {
module.copyValues(mapper.readValue(stream.getInputStream(), module.getClass()));
} catch (Exception e) {
......@@ -961,7 +979,7 @@ public class MdaUtils {
}
public static String toJson(Object dataMap) {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = MdaEnv.getBean(ObjectMapper.class);
try {
return mapper.writeValueAsString(dataMap);
} catch (Exception e) {
......@@ -971,7 +989,7 @@ public class MdaUtils {
}
public static <T> T fromJson(String json, Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = MdaEnv.getBean(ObjectMapper.class);
return mapper.convertValue(json, clazz);
}
......
......@@ -10,8 +10,6 @@ import com.brilliance.mda.runtime.mda.impl.ModuleList;
import com.brilliance.mda.support.td.ModuleInfoManager;
import com.brilliance.mda.support.td.TDFieldInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.apache.commons.beanutils.MethodUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -60,12 +58,7 @@ public class Modules {
}
public static ObjectMapper getObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
// 在存盘的时候,不需要过滤字段,故 serializeAllExcept 不传参数
SimpleBeanPropertyFilter fieldFilter = SimpleBeanPropertyFilter.serializeAllExcept();
filterProvider.addFilter("fieldFilter", fieldFilter);
objectMapper.setFilterProvider(filterProvider);
ObjectMapper objectMapper = MdaEnv.getBean(ObjectMapper.class);
return objectMapper;
}
......@@ -81,7 +74,7 @@ public class Modules {
}
public static Object data2Module(Class clazz, String dataString) {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = MdaEnv.getBean(ObjectMapper.class);
try {
boolean isEnableNotify = DCR.isEnable();
if (isEnableNotify)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment