引入 jackson

This commit is contained in:
bwcx_jzy 2019-11-14 22:42:34 +08:00
parent ea379f38a9
commit 28882f7256
4 changed files with 56 additions and 3 deletions

View File

@ -6,7 +6,7 @@
1. 【Agent】 nginx管理支持自定义编译运行管理方式变更
2. 【Server】 监控通知新增企业微信(感谢@TinyBao。
3. 管理脚本支持自动识别环境变量和java路径
3. 管理脚本支持自动识别环境变量和java路径linux环境
4. 项目类型新增File(快速管理纯静态文件)
### 解决BUG、优化功能

View File

@ -0,0 +1,14 @@
package io.jpom.controller.manage.jdk;
import io.jpom.common.BaseAgentController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author bwcx_jzy
* @date 2019/11/1
*/
@RestController
@RequestMapping(value = "/manage/jdk/")
public class JdkListController extends BaseAgentController {
}

View File

@ -1,11 +1,19 @@
package io.jpom;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.system.SystemUtil;
import cn.jiangzeyin.common.ApplicationBuilder;
import cn.jiangzeyin.common.validator.ParameterInterceptor;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.jpom.common.JpomApplicationEvent;
import io.jpom.common.JpomManifest;
import io.jpom.common.Type;
@ -13,6 +21,8 @@ import io.jpom.common.interceptor.PluginFeatureInterceptor;
import io.jpom.plugin.PluginFactory;
import io.jpom.util.CommandUtil;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import java.io.File;
import java.nio.charset.Charset;
@ -58,6 +68,10 @@ public class JpomApplication extends ApplicationBuilder {
addHttpMessageConverter(new StringHttpMessageConverter(CharsetUtil.CHARSET_UTF_8));
//
ObjectMapper build = createJackson();
addHttpMessageConverter(new MappingJackson2HttpMessageConverter(build));
// 参数拦截器
addInterceptor(ParameterInterceptor.class);
addInterceptor(PluginFeatureInterceptor.class);
@ -67,6 +81,31 @@ public class JpomApplication extends ApplicationBuilder {
this.application().addInitializers(new PluginFactory());
}
/**
* jackson 配置
*
* @return mapper
*/
private static ObjectMapper createJackson() {
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder = Jackson2ObjectMapperBuilder.json();
jackson2ObjectMapperBuilder.simpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
ObjectMapper build = jackson2ObjectMapperBuilder.build();
// 忽略空
build.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// 驼峰转下划线
// build.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());
// long to String
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
build.registerModule(simpleModule);
//
build.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// build.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
return build;
}
private void checkEvent(String[] args) throws Exception {
new JpomClose().main(args);
}

View File

@ -54,7 +54,7 @@ public class SshController extends BaseServerController {
@RequestMapping(value = "list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@Feature(method = MethodFeature.LIST)
public String listData() {
public JsonMessage<List<SshModel>> listData() {
List<SshModel> list = sshService.list();
if (list != null) {
List<NodeModel> list1 = nodeService.list();
@ -73,7 +73,7 @@ public class SshController extends BaseServerController {
sshModel.setNodeModel(nodeModel);
});
}
return JsonMessage.getString(200, "", list);
return new JsonMessage<>(200, "", list);
}
@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)