描述:
我新建了一个实体类,但是实体类的首字母是大写的,但是使用fastjson后打印的,Json字符串首字母却是小写的,这是fastjson的一个bug
实体类:

Json字符串:

解决方法:
一、使用@JSONField注解
实体类上使用@JSONField注解以后就变正常了。


代码修改如下:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderDto {
@JSONField(name = "OuterOrderNo")
private String OuterOrderNo;
@JSONField(name = "ShippingMethodId")
private Long ShippingMethodId;
}
二、使用Gson
代码修改如下:
@Test
public void testJson() {
OrderDto orderDto = new OrderDto();
orderDto.setOuterOrderNo("123");
orderDto.setShippingMethodId(1L);
Gson gson = new Gson();
String jsonString = gson.toJson(orderDto);
System.out.println("jsonString = " + jsonString);
}
运行效果:







![【YOLOv8改进[Backbone]】使用MobileNetV3助力YOLOv8网络结构轻量化并助力涨点](https://img-blog.csdnimg.cn/direct/f4e46c4ccc8d4252ba4ba71cb80d1551.png)












![洛谷 P1131 [ZJOI2007] 时态同步](https://img-blog.csdnimg.cn/direct/eb5718ac450d498bbfa753b0db803f52.png)