[英]How to add custom header with <String, Integer> to Spring Boot HttpHeaders?
[英]Create custom java json spring boot parser for map<string, integer>
錯誤JSON parse error: Cannot coerce empty String ("") to element of `java.util.LinkedHashMap<java.lang.String,java.lang.Integer>`
當 http 請求類似於field: {"one": 1}
那么它可以工作
但是,該field
可以為空,有時會出現一個 http 請求,其中字段類似於field: ""
是否可以創建一個轉換器來檢查字符串是 null 還是空白,然后返回 null 而不嘗試將其解析為 map 並得到錯誤?
我猜你可以使用可選的。
是的,你可以轉換它。
這是一個嘗試在不使用 Optional 的情況下設置可能為 Null 的值的示例。
例如,在從Map<String, Object>
node
獲取值之后,我試圖設置spent_hours
時間
setSpent_hours(node.get("total_spent_hours")== null ? "N/A" :node.get("total_spent_hours").toString());
這基本上是將值設置為保持值 null 的N/A
瞬間字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.