Skip to content

Commit 060de65

Browse files
committed
Support global JxDecoder, re #23
1 parent 26946a6 commit 060de65

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

binding/src/main/java/org/jsonx/JxDecoder.java

+38
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,44 @@ public final class JxDecoder {
3333
public static final JxDecoder VALIDATING = new JxDecoder(true);
3434
public static final JxDecoder NON_VALIDATING = new JxDecoder(false);
3535

36+
private static JxDecoder global = NON_VALIDATING;
37+
38+
/**
39+
* Returns the {@link JxDecoder} for the provided validation boolean,
40+
* specifying whether the {@link JxDecoder} is to validate JSON documents
41+
* while parsing.
42+
*
43+
* @param validating Whether the {@link JxDecoder} is to validate JSON
44+
* documents while parsing.
45+
* @return The {@link JxDecoder} for the provided validation boolean,
46+
* specifying whether the {@link JxDecoder} is to validate JSON
47+
* documents while parsing.
48+
*/
49+
public static JxDecoder get(final boolean validating) {
50+
return validating ? VALIDATING : NON_VALIDATING;
51+
}
52+
53+
/**
54+
* Returns the global {@link JxDecoder}.
55+
*
56+
* @return The global {@link JxDecoder}.
57+
* @see #set(JxDecoder)
58+
*/
59+
public static JxDecoder get() {
60+
return global;
61+
}
62+
63+
/**
64+
* Set the global {@link JxDecoder}.
65+
*
66+
* @param decoder The {@link JxDecoder}.
67+
* @return The provided {@link JxDecoder}.
68+
* @see #get()
69+
*/
70+
public static JxDecoder set(final JxDecoder decoder) {
71+
return global = decoder;
72+
}
73+
3674
private final boolean validate;
3775

3876
private JxDecoder(final boolean validate) {

binding/src/main/java/org/jsonx/JxEncoder.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ public static JxEncoder get() {
9494
* Set the global {@link JxEncoder}.
9595
*
9696
* @param encoder The {@link JxEncoder}.
97+
* @return The provided {@link JxEncoder}.
9798
* @see #get()
9899
*/
99-
public static void set(final JxEncoder encoder) {
100-
global = encoder;
100+
public static JxEncoder set(final JxEncoder encoder) {
101+
return global = encoder;
101102
}
102103

103104
final int indent;

0 commit comments

Comments
 (0)