gpt4 book ai didi

java - objectMapper 将印地语文本转换为特殊字符 "???"

转载 作者:行者123 更新时间:2023-12-02 12:28:10 28 4
gpt4 key购买 nike

我正在将印地语存储在数据库中。在我的 fetch 方法中,我使用 objectMapper 它将印地语字体转换为特殊字符。没有objectmapper它工作正常。

@CrossOrigin
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> fetchDepartmentInfo() {
try {
List<Map<String, Object>> departmentList = departmentServices.fetchDepartments();

if (departmentList == null || departmentList.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else
return new ResponseEntity<String>(new ObjectMapper().writeValueAsString(departmentList), HttpStatus.OK);
} catch (Exception e) {
System.out.println(e);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

o/p:

[
{
"department": "?? ?? ?????",
"departmentId": 1
}
]

但应该是:

[
{
"department": "जल कल विभाग",
"departmentId": 1
}
]

最佳答案

刚刚将 mediaType 更改为 APPLICATION_JSON_UTF8_VALUE

@CrossOrigin
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<?> fetchDepartmentInfo() {
try {
List<Map<String, Object>> departmentList = departmentServices.fetchDepartments();

if (departmentList == null || departmentList.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else
return new ResponseEntity<String>(new ObjectMapper().writeValueAsString(departmentList), HttpStatus.OK);
} catch (Exception e) {
System.out.println(e);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

它解决了我的问题。

关于java - objectMapper 将印地语文本转换为特殊字符 "???",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45397929/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com