question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No Converter found for ByteString to String

See original GitHub issue

Describe the bug When I’m using spring cloud openfeing with a custom configuration that has injected properties values with @Value annotation that are obtained from google secret manager I’m getting the following error nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.google.protobuf.ByteString$LiteralByteString] to type [java.lang.String]"}

I made a example project with the use of this type of configuration but it does not work cause I do not have a gcp subscription, but you can get the idea.

application.properties AUTH_CREDENTIALS=${sm://secret}

As a summary I have the configuration file for feign similar to the following one

@Value("${AUTH_CREDENTIALS}") //These credentials are store in this way username:password so I need to encode and add to header

  private String authCredentials;

  @Bean
  public RequestInterceptor basicAuthRequestInterceptor(){
    return new CustomBasicAuthRequestInterceptor(authCredentials);
  }

An a feign client that uses the configuration

@FeignClient(value = "restClient", url = "${REST_URL}", configuration = CustomBasicAuthConfiguration.class)
public interface RestClient {

    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    String request();
}

The request interceptor

    private String headerValue;

    public CustomBasicAuthRequestInterceptor(String authCredentials) {
        this(authCredentials, StandardCharsets.UTF_8);
    }

    public CustomBasicAuthRequestInterceptor(String authCredentials, Charset charset) {
        this.headerValue = "Basic " + new String(Base64.getEncoder().encode(authCredentials.getBytes(charset)));
    }

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header("Authorization", headerValue);
    }

When I’m using this way I get the exception described above, but when I annotated with @Component I don’t get the exception. I prefer the first way because I have several feign clients and this one needs this configuration.

Also in the example project you will find a workaround that was answered here

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JoeWang1127commented, Oct 6, 2022

Hi @danielalejandrin and @damienburke, the latest version of this project solves this problem and you don’t need to define a converter, but it’s not released yet. My suggestion is you can keep the workaround for now and change it when we official release the next version.

0reactions
JoeWang1127commented, Nov 17, 2022

Hi @bjeon-bakkt, you can try 3.4.0. Could you post a sample project which reproduce the issue in a Github repo?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No converter found capable of converting from type [com ...
If I annotate the class with de @Configuration it parses the ByteString to String but it applies to all the feign clients and...
Read more >
no converter found capable of converting from type string
Needed a custom Entity class so created one. Application starts but when I hit the query I get below error : org.springframework.core.convert.
Read more >
“HttpMessageNotWritableException: No converter found for ...
In this tutorial, we're going to shed light on Spring's HttpMessageNotWritableException: “No converter found for return value of type” ...
Read more >
How to convert byte[] array to String in Java - Mkyong.com
For text data `byte[]`, we use `new String(bytes, StandardCharsets. ... address of the object in memory, NOT converting byte[] to a string !...
Read more >
6. Content Type and Transformation - Spring
Where JSON represents either a byte array or String payload containing JSON. ... channel is already a String so no conversion will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found