fastjson Spring RestController 返回类型为map< Long, Object>时格式错误, long 数据多了一层双引号

e3bfsja2  于 6个月前  发布在  Spring
关注(0)|答案(2)|浏览(115)

示例ctrl:
@RestController
@RequestMapping("/test/")
public class TestCtrl {
@GetMapping(value = "getMapInfo")
@ApiOperation(value = "获取MAP信息")
public Map<Long, String> getMapInfo(){
return ImmutableMap.of(-1L, "");
}
}
//fastJsonHttpMessageConverter设置全局参数
FastJsonConfig config = new FastJsonConfig();
//Long类型转String类型
SerializeConfig serializeConfig = SerializeConfig.globalInstance;
serializeConfig.put(Long.class, ToStringSerializer.instance);
serializeConfig.put(BigInteger.class, ToStringSerializer.instance);
serializeConfig.put(Long.TYPE, ToStringSerializer.instance);
config.setSerializeConfig(serializeConfig);
config.setSerializerFeatures(SerializerFeature.BrowserSecure,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteNullBooleanAsFalse,
SerializerFeature.WriteDateUseDateFormat,
SerializerFeature.DisableCircularReferenceDetect
);
config.setCharset(StandardCharsets.UTF_8);
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
fastJsonHttpMessageConverter.setFastJsonConfig(config);
//错误输出如下:
{
""-1"": ""
}

j9per5c4

j9per5c41#

错误类及代码截图

k3bvogb1

k3bvogb12#

建议将改行代码调整为:TypeUtils.cast(entryKey, String.class, null);

相关问题