public interface Encoder
javax.websocket.Encoder
. Encoder
is used when a method parameter has no @Param
annotation. For example: @POST @Path("/") void create(User user);Example implementation:
public class GsonEncoder implements Encoder { private final Gson gson; public GsonEncoder(Gson gson) { this.gson = gson; } @Override public void encode(Object object, Type bodyType, RequestTemplate template) { template.body(gson.toJson(object, bodyType)); } }
If any parameters are found in MethodMetadata.formParams()
, they will be collected
and passed to the Encoder as a map.
Ex. The following is a form. Notice the parameters aren't consumed in the request line. A map
including "username" and "password" keys will passed to the encoder, and the body type will be
MAP_STRING_WILDCARD
.
@RequestLine("POST /") Session login(@Param("username") String username, @Param("password") String password);
Modifier and Type | Interface and Description |
---|---|
static class |
Encoder.Default
Default implementation of
Encoder . |
Modifier and Type | Field and Description |
---|---|
static Type |
MAP_STRING_WILDCARD
Type literal for
Map<String, ?> , indicating the object to encode is a form. |
Modifier and Type | Method and Description |
---|---|
void |
encode(Object object,
Type bodyType,
RequestTemplate template)
Converts objects to an appropriate representation in the template.
|
static final Type MAP_STRING_WILDCARD
Map<String, ?>
, indicating the object to encode is a form.void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException
object
- what to encode as the request body.bodyType
- the type the object should be encoded as. MAP_STRING_WILDCARD
indicates form encoding.template
- the request template to populate.EncodeException
- when encoding failed due to a checked exception.Copyright © 2012–2020 OpenFeign. All rights reserved.