国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html
内部邀请码:C8E245J (不写邀请码,没有现金送)
国内私募机构九鼎控股打造,九鼎投资是在全国股份转让系统挂牌的公众公司,股票代码为430719,为中国PE第一股,市值超1000亿元。 

------------------------------------------------------------------------------------------------------------------------------------------------------------------

1) 国产开源软件要支持的

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.1</version>
</dependency>

2) spring没有提供相应的HttpMessageConverter可以自己写一个。

package com.alibaba.fastjson.spring.support;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset; import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature; public class MappingFastJsonHttpMessageConverter extends AbstractHttpMessageConverter<Object> { public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); // fastjson特性参数
private SerializerFeature[] serializerFeature; public SerializerFeature[] getSerializerFeature() {
return serializerFeature;
} public void setSerializerFeature(SerializerFeature[] serializerFeature) {
this.serializerFeature = serializerFeature;
} public MappingFastJsonHttpMessageConverter() {
super(new MediaType("application", "json", DEFAULT_CHARSET));
} @Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
// JavaType javaType = getJavaType(clazz);
// return this.objectMapper.canDeserialize(javaType) &&
// canRead(mediaType);
return true;
} @Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
// return this.objectMapper.canSerialize(clazz) && canWrite(mediaType);
return true;
} @Override
protected boolean supports(Class<?> clazz) {
// should not be called, since we override canRead/Write instead
throw new UnsupportedOperationException();
} @Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = inputMessage.getBody().read()) != -1) {
baos.write(i);
}
return JSON.parseArray(baos.toString(), clazz);
} @Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
String jsonString = JSON.toJSONString(o, serializerFeature);
OutputStream out = outputMessage.getBody();
out.write(jsonString.getBytes(DEFAULT_CHARSET));
out.flush();
} }

3) 配置

<mvc:annotation-driven>
<mvc:message-converters register-defaults="true" >
<bean class="com.alibaba.fastjson.spring.support.MappingFastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json" />
<property name="serializerFeature">
<array>
<value>WriteMapNullValue</value>
<value>QuoteFieldNames</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

SpringMVC杂记(1) 使用阿里巴巴的fastjson的更多相关文章

  1. Springmvc使用阿里巴巴的fastjson传输到前台中文乱码的解决方案,他娘的大家都少制造垃圾,学习过程将会多么快乐

    弄了大概七八个小时吧 都他妈比的抄来抄去,一分一秒的去试错 最终参考这个问题解决了乱码的情况https://bbs.csdn.net/topics/392169549 412 需要在springmvc ...

  2. SpringMVC:JSON形式输出(基于Fastjson)

    在Spring3.0中,@ResponseBody标记可以将对象"封装"为JSON形式的数据,并输出,下面的例子中使用的是阿里的Fastjson JSONaz解析工具,在sprin ...

  3. 解析Json的谷歌官方方法Gson和阿里巴巴的fastJson方法。

    //测试单个json文本 public void testGsonTwo(){ String jsonStr = "{\"id\":100,\"name\&qu ...

  4. 阿里巴巴json fastjson String转javaBean

    private Entity getEntity(String resp){        JSONObject jsonObj = (JSONObject) JSON.parse(resp);    ...

  5. 阿里巴巴fastJson

    FastJson解析 一.阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java ...

  6. springmvc与fastjson的整合,注解@RequestBody的使用

    项目内容用的是jetty框架,传输数据格式是json格式,有一天我心血来潮,把项目又搭建了一次,完了,卡在了数据传输的格式上,明明原来框架直接用fastjson,但是我用就是不对,总是报fastjso ...

  7. SpringMVC整合fastjson、easyui 乱码问题

    一.框架版本 SpringMVC:3.1.1.RELEASE fastjson:1.2.7 easyui :1.4.5 二.乱码现象    Action中使用@ResponseBody返回Json数据 ...

  8. SpringMVC中post请求参数注解@requestBody使用问题

    一.httpClient发送Post 原文https://www.cnblogs.com/Vdiao/p/5339487.html public static String httpPostWithJ ...

  9. SpringMVC: JSON

    SpringMVC:JSON讲解 什么是JSON? JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式,目前使用特别广泛. 采用完全独立于编 ...

随机推荐

  1. Linux下var目录介绍

    var目录 /var 包括系统运行时要改变的数据.其中包括每个系统是特定的,即不能够与其他计算机共享的目录,如/var/log,/var/lock,/var/run.有些目录还是可以与其他系统共享,如 ...

  2. you have to first modify the default Eclipse configuration to avoid XML cosmetic errors:

    Configure XML Validation to Avoid Cosmetic Errors Navigate to: Window->Preferences->XML->XM ...

  3. iOS控制器与视图加载方法

    转载记录, 请看原文: 1. iOS中的各种加载方法(initWithNibName,loadNibNamed,initWithCoder,awakeFromNib等等)简单使用   http://w ...

  4. poj1915 Knight Moves(BFS)

    题目链接 http://poj.org/problem?id=1915 题意 输入正方形棋盘的边长.起点和终点的位置,给定棋子的走法,输出最少经过多少步可以从起点走到终点. 思路 经典bfs题目. 代 ...

  5. PHP 5.4 内置 web 服务器

    之前 OSC 翻译了一篇文章:在 Windows 上使用 PHP 5.4 内置的 Web 服务器 下面这篇文章来自外刊IT评论翻译的在 Linux 下使用 PHP 5.4 内置 Web 服务器 PHP ...

  6. mcnp的重复探测器单元计数-fmesh卡的介绍

    第一步:首先前面是cell surface和material等的定义,忽略,然后写上下面的这些抽样信息等.最后写入fmesh卡的信息定义 第二步:计算上述输入卡,得到结果,显然不在outx,x代表p ...

  7. property staticmathod classmethod 反射

    使用@property 在绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单,但是,没办法检查参数,导致可以把成绩随便改: s = Student() s.score = 9999 这显然不合逻 ...

  8. HDU2874【倍增、ST】

    题目链接[https://vjudge.net/problem/HDU-2874] 题意: 输入一个森林,总节点不超过N(N<10000),由C次询问(C<1000000),每次询问两个点 ...

  9. SPOJ375 Query on a tree 【倍增,在线】

    题目链接[http://www.spoj.com/problems/QTREE/] 题意:给出一个包含N(N<=10000)节点的无根树,有多次询问,询问的方式有两种1.DIST  a b 求a ...

  10. SCOI2011 棘手的操作

    线段树+并查集,对于每个操作我们只需要维护他在自己子树中的最值和在整个树里的最值,类似于线段树动态开点. #include<bits/stdc++.h> using namespace s ...