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.

Should the documentation have an example for how to use multiple decoders?

See original GitHub issue

In my implementation I need to use the default decoder for byte[] and GsonDecoder to map to objects and I’m doing the following in Java 11:

@Bean
    public Decoder decoder() {
        Decoder decoder = (response, type) -> {
            if (type.getTypeName().equals("java.lang.String") ||
                    type.getTypeName().equals("byte[]")
            ) {
                return new Decoder.Default().decode(response, type);
            } else {
                return new GsonDecoder().decode(response, type);
            }
        };
        return new ResponseEntityDecoder(decoder);
    }

Is this worth having an example in the documentation? I was inspired by this discussion https://github.com/spring-cloud/spring-cloud-netflix/issues/2246

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sshevlyagincommented, Jul 24, 2020

That sounds way better @velo. My scenario was the API returns image/jpeg or application/json depending on which endpoint you hit.

re: wiki, no need to give me write access you can just copy/paste that gist if you want

1reaction
velocommented, Jul 24, 2020

@sshevlyagin what if we added a new #decoder(MediaType,Decoder) to Feign.Builder

Invoking decoder(Decoder) would overwrite the decoder as is today. Invoking decoder(MediaType,Decoder) would replace decoder with a TypedDecoder, and would assign the existing decoder to media-type */* Subsequent invocations of decoder(MediaType,Decoder) would append a new Decoder to the TypedDecoder. If MediaType already registered on TypedDecoder log warning and replace.

TypedDecoder would be a implementation of Decoder that checks the MediaType first and then delegate the decoding process to Decoder

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encoding and Decoding Custom Types - Apple Developer
Make your data types encodable and decodable for compatibility with external representations such as JSON.
Read more >
Encoder Decoder Models - Hugging Face
It is used to instantiate an Encoder Decoder model according to the specified arguments, defining the encoder and decoder configs. Configuration objects ...
Read more >
codecs — Codec registry and base classes — Python 3.11.1 ...
The IncrementalDecoder class is used for decoding an input in multiple steps. It defines the following methods which every incremental decoder must define...
Read more >
Decoders Syntax - Ruleset XML syntax - Wazuh documentation
A parent decoder can have many child decoders but take into account that a ... Example: Decoder_junior will enter only if decoder_parent has...
Read more >
Writing a custom encoder or decoder - EasyVVUQ
For example, GenericEncoder uses text substitution in a user provided template. ... However, many large, established simulation packages have more complex ...
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