Skip to content

Commit 6b6391c

Browse files
committed
improve javadoc
1 parent b0e4e3e commit 6b6391c

13 files changed

+188
-11
lines changed

jsonb/src/main/java/io/avaje/jsonb/JsonType.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,32 @@
88
/**
99
* Provides API to serialise a type to and from JSON.
1010
* <p>
11-
* JsonType provides the main API that is used to convert to and from json.
11+
* JsonType provides the main API used to read and write json.
12+
*
13+
* <h4>fromJson</h4>
14+
* <p>
15+
* Read json content from: String, byte[], Reader, InputStream, JsonReader
16+
* </p>
17+
* <pre>{@code
18+
*
19+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
20+
*
21+
* Customer customer = customerType.fromJson(content);
22+
*
23+
* }</pre>
24+
*
25+
* <h4>toJson</h4>
26+
* <p>
27+
* Write json content to: String, byte[], Writer, OutputStream, JsonWriter
28+
* </p>
29+
* <pre>{@code
30+
*
31+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
32+
*
33+
* String asJson = customerType.toJson(customer);
34+
*
35+
* }</pre>
36+
*
1237
* <p>
1338
* Moshi note: JsonType does not exist in Moshi and has been added to provide a
1439
* slightly nicer API to use than JsonAdapter.

jsonb/src/main/java/io/avaje/jsonb/Jsonb.java

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,43 @@
1212
/**
1313
* Provides access to json adapters by type.
1414
*
15-
* <pre>{@code
15+
* <h4>Initialise with defaults</h3>
1616
*
17+
* <pre>{@code
1718
* Jsonb jsonb = Jsonb.newBuilder().build();
19+
* }</pre>
1820
*
19-
* JsonType<Customer> customerType = jsonb.type(Customer.class);
21+
* <h4>Initialise with some configuration</h3>
2022
*
21-
* Customer customer = ...;
23+
* <pre>{@code
24+
* Jsonb jsonb = Jsonb.newBuilder()
25+
* .serializeNulls(true)
26+
* .serializeEmpty(true)
27+
* .failOnUnknown(true)
28+
* .build();
29+
* }</pre>
30+
*
31+
* <h4>fromJson</h4>
32+
* <p>
33+
* Read json content from: String, byte[], Reader, InputStream, JsonReader
34+
* </p>
35+
* <pre>{@code
36+
*
37+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
38+
*
39+
* Customer customer = customerType.fromJson(content);
40+
*
41+
* }</pre>
42+
*
43+
* <h4>toJson</h4>
44+
* <p>
45+
* Write json content to: String, byte[], Writer, OutputStream, JsonWriter
46+
* </p>
47+
* <pre>{@code
2248
*
23-
* // write json
24-
* String asJson = customerType.toJson(customer);
49+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
2550
*
26-
* // read json
27-
* Customer customer = customerType.fromJson(asJson);
51+
* String asJson = customerType.toJson(customer);
2852
*
2953
* }</pre>
3054
*/
@@ -38,6 +62,16 @@ public interface Jsonb {
3862
* <p>
3963
* Note that JsonAdapter's that are generated are automatically registered via service
4064
* loading so there is no need to explicitly register those generated JsonAdapters.
65+
*
66+
* <pre>{@code
67+
*
68+
* Jsonb jsonb = Jsonb.newBuilder()
69+
* .serializeNulls(true)
70+
* .serializeEmpty(true)
71+
* .failOnUnknown(true)
72+
* .build();
73+
*
74+
* }</pre>
4175
*/
4276
static Builder newBuilder() {
4377
Iterator<Bootstrap> bootstrapService = ServiceLoader.load(Bootstrap.class).iterator();

jsonb/src/main/java/io/avaje/jsonb/core/DefaultBootstrap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import io.avaje.jsonb.Jsonb;
44

5+
/**
6+
* Default bootstrap of Jsonb.
7+
*/
58
public class DefaultBootstrap {
69

10+
/**
11+
* Create the Jsonb.Builder.
12+
*/
713
public static Jsonb.Builder newBuilder() {
814
return new DJsonb.DBuilder();
915
}

jsonb/src/main/java/io/avaje/jsonb/core/Util.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.lang.reflect.*;
2020
import java.util.*;
2121

22+
/**
23+
* Utility methods for defining Types.
24+
*/
2225
public final class Util {
2326

2427
static final Type[] EMPTY_TYPE_ARRAY = new Type[]{};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Core internal implementation.
3+
*/
4+
package io.avaje.jsonb.core;

jsonb/src/main/java/io/avaje/jsonb/jackson/JacksonAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313

1414
import java.io.*;
1515

16+
/**
17+
* Jackson Core implementation of IOAdapter.
18+
*/
1619
public class JacksonAdapter implements IOAdapter {
1720

1821
private final JsonFactory jsonFactory;
1922
private final boolean serializeNulls;
2023
private final boolean serializeEmpty;
2124
private final boolean failOnUnknown;
2225

26+
/**
27+
* Create with the given default configuration.
28+
*/
2329
public JacksonAdapter(boolean serializeNulls, boolean serializeEmpty, boolean failOnUnknown) {
2430
this.serializeNulls = serializeNulls;
2531
this.serializeEmpty = serializeEmpty;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Uses Jackson Core JsonGenerator and JsonParser to implement the SPI.
3+
*/
4+
package io.avaje.jsonb.jackson;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Core API of Jsonb.
3+
*
4+
* <h4>Initialise with defaults</h3>
5+
*
6+
* <pre>{@code
7+
* Jsonb jsonb = Jsonb.newBuilder().build();
8+
* }</pre>
9+
*
10+
* <h4>Initialise with some configuration</h3>
11+
*
12+
* <pre>{@code
13+
* Jsonb jsonb = Jsonb.newBuilder()
14+
* .serializeNulls(true)
15+
* .serializeEmpty(true)
16+
* .failOnUnknown(true)
17+
* .build();
18+
* }</pre>
19+
*
20+
* <h4>fromJson</h4>
21+
* <p>
22+
* Read json content from: String, byte[], Reader, InputStream, JsonReader
23+
* </p>
24+
* <pre>{@code
25+
*
26+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
27+
*
28+
* Customer customer = customerType.fromJson(content);
29+
*
30+
* }</pre>
31+
*
32+
* <h4>toJson</h4>
33+
* <p>
34+
* Write json content to: String, byte[], Writer, OutputStream, JsonWriter
35+
* </p>
36+
* <pre>{@code
37+
*
38+
* JsonType<Customer> customerType = jsonb.type(Customer.class);
39+
*
40+
* String asJson = customerType.toJson(customer);
41+
*
42+
* }</pre>
43+
*
44+
* @see io.avaje.jsonb.Jsonb
45+
* @see io.avaje.jsonb.JsonType
46+
*/
47+
package io.avaje.jsonb;

jsonb/src/main/java/io/avaje/jsonb/spi/Bootstrap.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
import io.avaje.jsonb.Jsonb;
44

5+
/**
6+
* Bootstrap Jsonb.
7+
*/
58
public interface Bootstrap {
69

10+
/**
11+
* Create and return a Builder (with an underling SPI implementation).
12+
* <p>
13+
* The default implementation uses Jackson Core.
14+
*/
715
Jsonb.Builder newBuilder();
816
}

jsonb/src/main/java/io/avaje/jsonb/spi/DelegateJsonWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import io.avaje.jsonb.JsonWriter;
44

5-
import java.io.IOException;
65
import java.math.BigDecimal;
76

7+
/**
8+
* Provides a delegating JsonWriter.
9+
*/
810
public abstract class DelegateJsonWriter implements JsonWriter {
911

1012
protected final JsonWriter delegate;

0 commit comments

Comments
 (0)