[英]Java Map empty string value is omitted when sending response to postman
My map is: Map<String, String>.我的 map 是:Map<String, String>。 The issue is empty values are not sended to the postman even though when I debbug are there.
问题是空值不会发送到 postman 即使我在那里调试。
This is the api:这是 api:
@GetMapping(value = Routes.URI_SUFFIX_DATA_ZIPCODES_BY_CITY_AND_ZIPCODE, produces = {MediaType.APPLICATION_JSON_VALUE})
@RegisterMetricCallReceived(appService = "getStreetsByCityAndZipCode", version = "v1", type = TYPE_REST)
public Map<String,String> getStreetsByCityAndZipCode(HttpServletRequest request,
@RequestParam(name = "city") String city,
@RequestParam(name = "zipcode") String zipcode) {
GetStreetByCityAndZipcode query = new GetStreetByCityAndZipcode();
query.setCity(city);
query.setZipcode(zipcode);
Map<String, String> result = service.getStreets("eligibility", query).orElse(null);
return result;
}
When I debugg result object, it's like that:当我调试结果 object 时,是这样的:
"PLACE DU PRIEURE" -> "01043406"
"ROUTE DE BIERNE" -> ""
"ROUTE DE GENNES SUR GLAIZE" -> "01043405"
"RUE COURTE" -> "01043399"
"RUE D ANJOU" -> "01043398"
"RUE DE GENNES" -> "04311435"
"RUE DE L EGLISE" -> "01043397"
"RUE DE LA CHENAIE" -> "04106244"
"RUE DE LA POSTE" -> "01043400"
"RUE DES GRANDS JARDINS" -> "01043401"
"RUE DES JARDINS" -> ""
"RUE DES SPORTS" -> "04415887"
But from postman, I don't receive this two:但是从 postman,我没有收到这两个:
"ROUTE DE BIERNE" -> ""
"RUE DES JARDINS" -> ""
I receive just others which have not empty values:我只收到其他没有空值的人:
"PLACE DU PRIEURE" -> "01043406"
"ROUTE DE GENNES SUR GLAIZE" -> "01043405"
"RUE COURTE" -> "01043399"
"RUE D ANJOU" -> "01043398"
"RUE DE GENNES" -> "04311435"
"RUE DE L EGLISE" -> "01043397"
"RUE DE LA CHENAIE" -> "04106244"
"RUE DE LA POSTE" -> "01043400"
"RUE DES GRANDS JARDINS" -> "01043401"
"RUE DES SPORTS" -> "04415887"
I found the issue, it was due to this Bean config, when I remove it, it works as fine:我发现了这个问题,这是由于这个 Bean 配置,当我删除它时,它可以正常工作:
@Bean
public JacksonFix jacksonFix(RequestMappingHandlerAdapter
annotationMethodHandlerAdapter) {
return new JacksonFix(annotationMethodHandlerAdapter);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.