Skip to content

Commit 473d145

Browse files
committed
update doc
1 parent f085ee1 commit 473d145

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

modules/jooby-yasson/src/main/java/org/jooby/json/Yasson.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,58 @@ public class Yasson implements Jooby.Module {
283283

284284
private boolean raw;
285285

286+
/**
287+
* Creates a new {@link Jsonb}.
288+
*
289+
* @param type {@link MediaType} to use.
290+
*/
286291
public Yasson(final MediaType type) {
287292
this.type = requireNonNull(type, "Media type is required.");
288293
}
289294

295+
/**
296+
* Creates a new {@link Jsonb} and set type to: {@link MediaType#json}.
297+
*
298+
*/
290299
public Yasson() {
291300
this(MediaType.json);
292301
}
293302

303+
/**
304+
* Configurer callback.
305+
*
306+
* <pre>
307+
* {
308+
* use(new Yasson().doWith(builder {@literal ->} {
309+
* builder.withFormatting(true);
310+
* // ...
311+
* });
312+
* }
313+
* </pre>
314+
*
315+
* @param configurer A callback.
316+
* @return This instance.
317+
*/
294318
public Yasson doWith(final BiConsumer<JsonbConfig, Config> configurer) {
295319
this.configurer = requireNonNull(configurer, "Configurer callback is required.");
296320
return this;
297321
}
298-
322+
323+
/**
324+
* Configurer callback.
325+
*
326+
* <pre>
327+
* {
328+
* use(new Yasson().doWith((builder, config) {@literal ->} {
329+
* builder.withFormatting(true);
330+
* // ...
331+
* });
332+
* }
333+
* </pre>
334+
*
335+
* @param configurer A callback.
336+
* @return This instance.
337+
*/
299338
public Yasson doWith(final Consumer<JsonbConfig> configurer) {
300339
requireNonNull(configurer, "Configurer callback is required.");
301340
this.configurer = (jsonConfig, conf) -> configurer.accept(jsonConfig);
@@ -314,8 +353,7 @@ public void configure(final Env env, final Config config, final Binder binder) {
314353

315354
binder.bind(Jsonb.class).toInstance(jsonb);
316355

317-
Multibinder.newSetBinder(binder, Parser.class).addBinding()
318-
.toInstance(new YassonParser(type, jsonb));
356+
Multibinder.newSetBinder(binder, Parser.class).addBinding().toInstance(new YassonParser(type, jsonb));
319357

320358
YassonRenderer renderer = raw ? new YassonRawRenderer(type, jsonb) : new YassonRenderer(type, jsonb);
321359

modules/jooby-yasson/src/main/java/org/jooby/json/YassonParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@
212212

213213
import com.google.inject.TypeLiteral;
214214

215+
/**
216+
* @author Daniel Dias
217+
* @since 1.6.0
218+
*/
215219
class YassonParser implements Parser {
216220

217221
private final MediaType type;
@@ -227,7 +231,6 @@ public YassonParser(final MediaType type, final Jsonb jsonb) {
227231
public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable {
228232
MediaType ctype = ctx.type();
229233
if (ctype.isAny()) {
230-
// */*
231234
return ctx.next();
232235
}
233236

@@ -243,4 +246,4 @@ public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwab
243246
public String toString() {
244247
return "yasson";
245248
}
246-
}
249+
}

modules/jooby-yasson/src/main/java/org/jooby/json/YassonRenderer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
import org.jooby.MediaType;
211211
import org.jooby.Renderer;
212212

213+
/**
214+
* @author Daniel Dias
215+
* @since 1.6.0
216+
*/
213217
public class YassonRenderer implements Renderer {
214218

215219
protected final MediaType type;
@@ -225,8 +229,7 @@ public YassonRenderer(final MediaType type, final Jsonb jsonb) {
225229
@Override
226230
public void render(final Object object, final Context ctx) throws Exception {
227231
if (ctx.accepts(this.type)) {
228-
ctx.type(this.type)
229-
.send(jsonb.toJson(object));
232+
ctx.type(this.type).send(jsonb.toJson(object));
230233
}
231234
}
232235

@@ -239,4 +242,4 @@ public String name() {
239242
public String toString() {
240243
return name();
241244
}
242-
}
245+
}

0 commit comments

Comments
 (0)