Tag: 春天休息

Spring Boot将文本/ JavaScript序列化为JSON

我创建了以下Kotlin数据类: @JsonInclude(JsonInclude.Include.NON_NULL) public data class ITunesArtist(val artistName: String, val artistId: Long, val artistLinkUrl: URL) (一个数据类是一个Kotlin类,在编译时自动生成equals,hashcode,toString等 – 节省时间)。 现在我试着使用Spring RestTemplate填充它: @Test fun loadArtist() { val restTemplate = RestTemplate() val artist = restTemplate.getForObject( "https://itunes.apple.com/search?term=howlin+wolf&entity=allArtist&limit=1", ITunesQueryResults::class.java); println("Got artist: $artist") } 它失败: Could not extract response: no suitable HttpMessageConverter found for response type [class vampr.api.service.authorization.facebook.ITunesArtist] and content type [text/javascript;charset=utf-8] […]

Spring REST,Kotin和默认的基本参数导致错误

我得到一个错误: 可选的长参数“count”存在,但由于被声明为基本类型而不能被转换为空值。 考虑将其声明为相应原始类型的对象包装 当我尝试调用这个REST控制器。 @RequestMapping("/api/audio/tracks", produces = arrayOf(APPLICATION_JSON_VALUE)) interface SomeApi { @RequestMapping(method = arrayOf(GET)) fun list(@RequestParam("count", defaultValue = "10") count: Long): Any } 不会春天看defaultValue吗? 如何解决这类问题? !Kotlin默认也不起作用