java json gson 属性 大写 首字母 大写
2017-01-04 17:49
2346 查看
问题描述:
项目中使用的是fastjson,在使用过程中遇到如下问题,在于.net数据交换时,因为.net给的json数据格式的属性首字母都是大写字母,例如:
{Name:"guyue",Age=23,sex="男"},在转换json的时候,数据无法封装上去。
解决办法:
修改json转换为gson,pom为<dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.0</version></dependency>,在vo属性中增加标注,@SerializedName("Name"),即可,另外本系统使用的是springmvc,在配置文件中
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
此配置为fastjson配置,如果想要接口输出也是通过gson,需要更改此配置,配置如下:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.GsonHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
写的很乱,只是作为记录,
项目中使用的是fastjson,在使用过程中遇到如下问题,在于.net数据交换时,因为.net给的json数据格式的属性首字母都是大写字母,例如:
{Name:"guyue",Age=23,sex="男"},在转换json的时候,数据无法封装上去。
解决办法:
修改json转换为gson,pom为<dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.0</version></dependency>,在vo属性中增加标注,@SerializedName("Name"),即可,另外本系统使用的是springmvc,在配置文件中
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
此配置为fastjson配置,如果想要接口输出也是通过gson,需要更改此配置,配置如下:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.GsonHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
写的很乱,只是作为记录,
相关文章推荐
- 使用Jackson2.4解析属性首字母为大写的JSON串
- Java操作JSON的便捷工具类(Gson)
- 很好用的Google 开源项目Gson在java中解析和创建json格式的数据
- gson将JSON字符串转成Java对象
- java json gson
- java转换json的实用工具-Gson
- gson(JSON字符串转换成一个相等的Java对象)
- Gson:Java格式化Json
- Android 使用GSON解析JSON 并转换为JAVA对象
- Gson--Json串生成Java对象
- 使用Gson将Java对象转换为JSON
- Google-gson, 将JSON 转换为 Java 对象或者将Java对象转换成JSON 的Java库,可以在Android上使用
- How to convert Java object to / from JSON (Gson)
- Java下json的解析方法-----GSON与JSONObject
- gson将JSON字符串转成Java对象
- 使用Gson将Java对象转换为Json
- google-gson - A Java library to convert JSON to Java objects and vice-versa
- Java gson使用 将Java对象转为Json 并 Json转回Java对象
- Java下json的解析方法-----GSON与JSONObject
- 使用Gson将Java对象转换为JSON