Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

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

Open
llm163520 opened this issue May 13, 2023 · 2 comments

Comments

@llm163520
Copy link

示例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"": ""
}

@llm163520
Copy link
Author

错误类及代码截图
image

@llm163520
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant