示例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"": ""
}
2条答案
按热度按时间j9per5c41#
错误类及代码截图
k3bvogb12#
建议将改行代码调整为:TypeUtils.cast(entryKey, String.class, null);