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));
}
}
MethodMetadata.formParams(), they will be collected and passed to the Encoder as a Map<String, ?>.
@POST
@Path("/")
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 | Method and Description |
|---|---|
void |
encode(java.lang.Object object,
java.lang.reflect.Type bodyType,
RequestTemplate template)
Converts objects to an appropriate representation in the template.
|
void encode(java.lang.Object object,
java.lang.reflect.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, ?>, if form
encoding.template - the request template to populate.EncodeException - when encoding failed due to a checked exception.