java.lang.Object
io.jooby.gson.GsonModule
- All Implemented Interfaces:
Extension,MessageDecoder,MessageEncoder
JSON module using Gson: https://github.com/google/gson.
Usage:
{
install(new GsonModule());
get("/", ctx -> {
MyObject myObject = ...;
// send json
return myObject;
});
post("/", ctx -> {
// read json
MyObject myObject = ctx.body(MyObject.class);
// send json
return myObject;
});
}
For body decoding the client must specify the Content-Type header set to
application/json.
You can retrieve the Gson object via require call:
{
Gson gson = require(Gson.class);
}
Complete documentation is available at: https://jooby.io/modules/gson.- Since:
- 2.7.2
- Author:
- edgar
-
Field Summary
Fields inherited from interface io.jooby.MessageDecoder
UNSUPPORTED_MEDIA_TYPEFields inherited from interface io.jooby.MessageEncoder
TO_STRING -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Gson module.GsonModule(com.google.gson.Gson gson) Creates a new module and use a Gson instance. -
Method Summary
-
Constructor Details
-
GsonModule
public GsonModule(@NonNull com.google.gson.Gson gson) Creates a new module and use a Gson instance.- Parameters:
gson- Gson to use.
-
GsonModule
public GsonModule()Creates a new Gson module.
-
-
Method Details
-
install
-
decode
- Specified by:
decodein interfaceMessageDecoder- Throws:
Exception
-
encode
- Specified by:
encodein interfaceMessageEncoder
-