Pramod
Pramod

Reputation: 411

Non ASCII characters not disaplayed when updating video with Feign

We use the Feign java client to update YouTube videos with YouTube data API V3. When updating the video if the video title or description contains non-ASCII characters then either they are treated as blank spaces (EX: Ä Ö Ü ß ä ö ü) or displayed as ???? (ex: ಆಂಟೆನಾ ಸ್ಥಾಪನೆ) Below is the method we use for updating the video

@RequestLine("PUT /videos?part=snippet,status,statistics&alt=json")
@Headers({"Authorization: {authToken}", "Accept: application/json;charset=UTF-8"})
@Body("%5B{uploadVideoDTO}%5D")
Video updateVideo(@Param("authToken") @NotBlank String authToken, @NotNull VideoUploadDTO uploadVideoDTO);

Below are the request details with Feign logs set to full Note: Earlier the Accept header was only application/json during that time the request was also logged with ???? in place of non-ASCII characters and after changing this to application/json;charset=UTF-8 at least the request is logged correctly and I assume also sent correctly.

 ---> PUT https://www.googleapis.com/youtube/v3/videos?part=snippet&part=status&part=statistics&alt=json HTTP/1.1
 Accept: application/json;charset=UTF-8
 Authorization: Bearer <BearerToken>
 Content-Length: 332
 
 {
  "id" : "15JCs1F_j50",
  "snippet" : {
    "title" : "ಆಂಟೆನಾ ಸ್ಥಾಪನೆ",
    "description" : "",
    "categoryId" : "27",
    "defaultLanguage" : "en",
    "tags" : [ ]
  },
  "status" : {
    "embeddable" : true,
    "selfDeclaredMadeForKids" : false,
    "privacyStatus" : "unlisted"
  }
}
---> END HTTP (332-byte body)

And in the response, the title is just a bunch of ?

 <--- HTTP/1.1 200 OK (1066ms)
 alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
 content-type: application/json; charset=UTF-8
 date: Thu, 30 Jan 2025 11:45:24 GMT
 server: scaffolding on HTTPServer2
 transfer-encoding: chunked
 vary: Origin
 vary: X-Origin
 vary: Referer
 x-content-type-options: nosniff
 x-frame-options: SAMEORIGIN
 x-xss-protection: 0
 
 {
  "kind": "youtube#video",
  "etag": "R8vO2esK8oIAIuzfFBlpDqM5-XM",
  "id": "15JCs1F_j50",
  "snippet": {
    "publishedAt": "2025-01-30T11:36:41Z",
    "channelId": "UCNhb_-2JbrBf4TL5_G6MkIw",
    "title": "?????? ???????",
    "description": "",
    "thumbnails": {
      <thumbnail_details>
    },
    "channelTitle": "Pramod A G",
    "categoryId": "27",
    "liveBroadcastContent": "none",
    "defaultLanguage": "en",
    "localized": {
      "title": "?????? ???????",
      "description": ""
    },
    "defaultAudioLanguage": "en-US"
  },
  "status": {
    <status>
  },
  "statistics": {
    <statistics>
  }
}

<--- END HTTP (1565-byte body)

Please help me fix this. We use java.net.HttpRequest for uploading the video and with that, the Unicode characters are properly decoded. There also we are not setting any special headers apart from Content-Tpe: Application/json and Content-Length. So I guess the issue is with Feign. I also checked if we are using any custom decoders, We use JacksonDecoder and by default, it decodes and encodes to UTF-8 so not sure what's wrong here.

Upvotes: 0

Views: 7

Answers (0)

Related Questions