标签:开源 long mvcc iba nts mvc new turn ali
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.33</version> </dependency>
添加依赖我们编写自己的类来继承
@Configuration public class FastJsonConfiguration extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = fastJsonHttpMessageConverter.getFastJsonConfig(); List<MediaType> fastMediaTypes = new ArrayList(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastJsonConfig.setSerializerFeatures( SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteMapNullValue ); fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); converters.add(fastJsonHttpMessageConverter); } }
三:自己的JSON类
package org.spring.springboot.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import java.io.Serializable; import java.util.List; public class MyJson<T> implements Serializable{ public static final int FAIL = 0; public static final int SUCCESS = 1; public static final int TOKEN = 2; public static final int OTHER = 9; private static final long serialVersionUID = -8528102467884030980L; private String msg = "success"; private int code = 1; private T data; public MyJson(T data) { this.data = data; } public <E> E converDataEntity(Class<E> clazz) { return JSON.parseObject(JSON.toJSONString(this.data, new SerializerFeature[]{SerializerFeature.WriteNonStringValueAsString}), clazz); } public JSONObject converDataJSONObject() { return JSON.parseObject(JSON.toJSONString(this.data, new SerializerFeature[]{SerializerFeature.WriteNonStringValueAsString})); } public <E> List<E> converDataArray(Class<E> clazz) { return JSON.parseArray(JSON.toJSONString(this.data, new SerializerFeature[]{SerializerFeature.WriteNonStringValueAsString}), clazz); } public JSONArray converDataJSONArray() { return JSON.parseArray(JSON.toJSONString(this.data, new SerializerFeature[]{SerializerFeature.WriteNonStringValueAsString})); } public String getMsg() { return this.msg; } public void setMsg(String msg) { this.msg = msg; } public int getCode() { return this.code; } public void setCode(int code) { this.code = code; } public T getData() { return this.data; } public void setData(T data) { this.data = data; } }
标签:开源 long mvcc iba nts mvc new turn ali
原文地址:https://www.cnblogs.com/bockpecehhe/p/9246481.html