This module provides support to application/json
using json-b, a Java spec to convert objects to/from json.
<dependency>
<groupId>com.github.ljtfreitas.julian-http-client</groupId>
<artifactId>julian-http-client-json-jsonb</artifactId>
<version>${julian-http-client-version}</version>
</dependency>
dependencies {
implementation("com.github.ljtfreitas.julian-http-client:julian-http-client-json-jsonb:$julianHttpClientVersion")
}
And that's it. HTTP requests and responses with application/json
media type will be serialized or deserialized using json-b
.
The main object from json-b
API is Jsonb. julian-http-client
creates an instance of it using default options, but we can customize that easily if we want:
import com.github.ljtfreitas.julian.ProxyBuilder;
import com.github.ljtfreitas.julian.http.codec.json.jsonb.JsonBHTTPMessageCodec;
import javax.json.bind.JsonBuilder;
import javax.json.bind.Jsonb;
Jsonb myJsonb = JsonBuilder.newBuilder()
// json-b configurations...
.build();
MyApi myApi = new ProxyBuilder()
.codecs()
.add(new JsonBHTTPMessageCodec(myJsonb))
.and()
.build(MyApi.class);