This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 59743b9 Context API refactoring.
59743b9 is described below
commit 59743b9a35b85e569500df0572897c3c61d71c21
Author: JamesBognar <[email protected]>
AuthorDate: Mon Sep 27 10:56:16 2021 -0400
Context API refactoring.
---
.../apache/juneau/serializer/WriterSerializer.java | 15 +++
.../java/org/apache/juneau/uon/ParamFormat.java | 2 +-
.../main/java/org/apache/juneau/uon/UonParser.java | 100 ++-------------
.../org/apache/juneau/uon/UonParserBuilder.java | 46 +++++--
.../org/apache/juneau/uon/UonParserSession.java | 10 +-
.../java/org/apache/juneau/uon/UonSerializer.java | 138 ++++-----------------
.../apache/juneau/uon/UonSerializerBuilder.java | 82 +++++++++---
.../apache/juneau/uon/UonSerializerSession.java | 10 +-
.../apache/juneau/uon/annotation/UonConfig.java | 12 +-
.../juneau/uon/annotation/UonConfigAnnotation.java | 45 +++++--
.../urlencoding/UrlEncodingSerializerSession.java | 2 +-
.../juneau/rest/client/RestClientBuilder.java | 4 +-
12 files changed, 196 insertions(+), 270 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializer.java
index 0409c4d..dbdfe37 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializer.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializer.java
@@ -186,6 +186,8 @@ public abstract class WriterSerializer extends Serializer {
private final Charset streamCharset;
private final boolean useWhitespace;
+ private final Character quoteCharRaw;
+
/**
* Constructor.
*
@@ -198,6 +200,8 @@ public abstract class WriterSerializer extends Serializer {
ContextProperties cp = getContextProperties();
maxIndent = cp.getInteger(WSERIALIZER_maxIndent).orElse(100);
quoteChar =
cp.getString(WSERIALIZER_quoteCharOverride).orElse(cp.getString(WSERIALIZER_quoteChar).orElse("\"")).charAt(0);
+ String _quoteCharRaw =
cp.getString(WSERIALIZER_quoteCharOverride).orElse(cp.getString(WSERIALIZER_quoteChar).orElse(null));
+ quoteCharRaw = _quoteCharRaw == null ? null :
_quoteCharRaw.charAt(0);
streamCharset = cp.get(WSERIALIZER_streamCharset,
Charset.class).orElse(IOUtils.UTF8);
fileCharset = cp.get(WSERIALIZER_fileCharset,
Charset.class).orElse(Charset.defaultCharset());
useWhitespace =
cp.getBoolean(WSERIALIZER_useWhitespace).orElse(false);
@@ -305,6 +309,17 @@ public abstract class WriterSerializer extends Serializer {
}
/**
+ * Quote character.
+ *
+ * @see #WSERIALIZER_quoteChar
+ * @return
+ * The character used for quoting attributes and values.
+ */
+ protected Character quoteChar() {
+ return quoteCharRaw;
+ }
+
+ /**
* Output stream charset.
*
* @see #WSERIALIZER_streamCharset
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/ParamFormat.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/ParamFormat.java
index 9b3d642..b17bd80 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/ParamFormat.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/ParamFormat.java
@@ -13,7 +13,7 @@
package org.apache.juneau.uon;
/**
- * Identifies the possible values for the {@link
UonSerializer#UON_paramFormat} setting.
+ * Identifies the possible values for the {@link
UonSerializerBuilder#paramFormat(ParamFormat)} setting.
*/
public enum ParamFormat {
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
index 9d96d2e..1a9be2e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
@@ -38,89 +38,7 @@ import org.apache.juneau.parser.*;
public class UonParser extends ReaderParser implements HttpPartParser,
UonMetaProvider {
//-------------------------------------------------------------------------------------------------------------------
- // Configurable properties
-
//-------------------------------------------------------------------------------------------------------------------
-
- static final String PREFIX = "UonParser";
-
- /**
- * Configuration property: Decode <js>"%xx"</js> sequences.
- *
- * <p>
- * <jk>true</jk> if URI encoded characters should be decoded,
<jk>false</jk> if they've already been decoded
- * before being passed to this parser.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.uon.UonParser#UON_decoding UON_decoding}
- * <li><b>Name:</b> <js>"UonParser.decoding.b"</js>
- * <li><b>Data type:</b> <jk>boolean</jk>
- * <li><b>System property:</b> <c>UonParser.decoding</c>
- * <li><b>Environment variable:</b> <c>UONPARSER_DECODING</c>
- * <li><b>Default:</b> <jk>false</jk> for {@link
org.apache.juneau.uon.UonParser}, <jk>true</jk> for {@link
org.apache.juneau.urlencoding.UrlEncodingParser}
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.uon.annotation.UonConfig#decoding()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.uon.UonParserBuilder#decoding()}
- * </ul>
- * </ul>
- */
- public static final String UON_decoding = PREFIX + ".decoding.b";
-
- /**
- * Configuration property: Validate end.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.uon.UonParser#UON_validateEnd UON_validateEnd}
- * <li><b>Name:</b> <js>"UonParser.validateEnd.b"</js>
- * <li><b>Data type:</b> <jk>boolean</jk>
- * <li><b>System property:</b> <c>UonParser.validateEnd</c>
- * <li><b>Environment variable:</b> <c>UONPARSER_VALIDATEEND</c>
- * <li><b>Default:</b> <jk>false</jk>
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.uon.annotation.UonConfig#validateEnd()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.uon.UonParserBuilder#validateEnd()}
- * </ul>
- * </ul>
- *
- * <h5 class='section'>Description:</h5>
- * <p>
- * If <jk>true</jk>, after parsing a POJO from the input, verifies that
the remaining input in
- * the stream consists of only comments or whitespace.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Create a parser using strict mode.</jc>
- * ReaderParser p = UonParser.
- * .<jsm>create</jsm>()
- * .validateEnd()
- * .build();
- *
- * <jc>// Same, but use property.</jc>
- * ReaderParser p = UonParser.
- * .<jsm>create</jsm>()
- * .set(<jsf>UON_validateEnd</jsf>)
- * .build();
- *
- * <jc>// Should fail because input has multiple POJOs.</jc>
- * String in = <js>"(foo=bar)(baz=qux)"</js>;
- * MyBean myBean = p.parse(in, MyBean.<jk>class</jk>);
- * </p>
- */
- public static final String UON_validateEnd = PREFIX + ".validateEnd.b";
-
-
//-------------------------------------------------------------------------------------------------------------------
- // Predefined instances
+ // Static
//-------------------------------------------------------------------------------------------------------------------
/** Reusable instance of {@link UonParser}, all default settings. */
@@ -129,9 +47,8 @@ public class UonParser extends ReaderParser implements
HttpPartParser, UonMetaPr
/** Reusable instance of {@link UonParser} with decodeChars set to
true. */
public static final UonParser DEFAULT_DECODING = new
UonParser.Decoding(create());
-
//-------------------------------------------------------------------------------------------------------------------
- // Predefined subclasses
+ // Static subclasses
//-------------------------------------------------------------------------------------------------------------------
/** Default parser, decoding. */
@@ -206,8 +123,8 @@ public class UonParser extends ReaderParser implements
HttpPartParser, UonMetaPr
// Instance
//-------------------------------------------------------------------------------------------------------------------
- private final boolean
- decoding, validateEnd;
+ final boolean decoding, validateEnd;
+
private final Map<ClassMeta<?>,UonClassMeta> uonClassMetas = new
ConcurrentHashMap<>();
private final Map<BeanPropertyMeta,UonBeanPropertyMeta>
uonBeanPropertyMetas = new ConcurrentHashMap<>();
@@ -218,9 +135,8 @@ public class UonParser extends ReaderParser implements
HttpPartParser, UonMetaPr
*/
protected UonParser(UonParserBuilder builder) {
super(builder);
- ContextProperties cp = getContextProperties();
- this.decoding = cp.getBoolean(UON_decoding).orElse(false);
- this.validateEnd = cp.getBoolean(UON_validateEnd).orElse(false);
+ decoding = builder.decoding;
+ validateEnd = builder.validateEnd;
}
@Override /* Context */
@@ -305,7 +221,7 @@ public class UonParser extends ReaderParser implements
HttpPartParser, UonMetaPr
/**
* Decode <js>"%xx"</js> sequences enabled
*
- * @see #UON_decoding
+ * @see UonParserBuilder#decoding()
* @return
* <jk>true</jk> if URI encoded characters should be decoded,
<jk>false</jk> if they've already been decoded
* before being passed to this parser.
@@ -317,7 +233,7 @@ public class UonParser extends ReaderParser implements
HttpPartParser, UonMetaPr
/**
* Validate end enabled.
*
- * @see #UON_validateEnd
+ * @see UonParserBuilder#validateEnd()
* @return
* <jk>true</jk> if after parsing a POJO from the input, verifies
that the remaining input in
* the stream consists of only comments or whitespace.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserBuilder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserBuilder.java
index 20d4bfb..e02abd3 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserBuilder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserBuilder.java
@@ -12,8 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau.uon;
-import static org.apache.juneau.uon.UonParser.*;
-
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.nio.charset.*;
@@ -31,6 +29,8 @@ import org.apache.juneau.parser.*;
@FluentSetters
public class UonParserBuilder extends ReaderParserBuilder {
+ boolean decoding, validateEnd;
+
/**
* Constructor, default settings.
*/
@@ -38,6 +38,8 @@ public class UonParserBuilder extends ReaderParserBuilder {
super();
consumes("text/uon");
type(UonParser.class);
+ decoding = env("UonParser.decoding", false);
+ validateEnd = env("UonParser.validateEnd", false);
}
/**
@@ -47,6 +49,8 @@ public class UonParserBuilder extends ReaderParserBuilder {
*/
protected UonParserBuilder(UonParser copyFrom) {
super(copyFrom);
+ decoding = copyFrom.decoding;
+ validateEnd = copyFrom.validateEnd;
}
/**
@@ -56,6 +60,8 @@ public class UonParserBuilder extends ReaderParserBuilder {
*/
protected UonParserBuilder(UonParserBuilder copyFrom) {
super(copyFrom);
+ decoding = copyFrom.decoding;
+ validateEnd = copyFrom.validateEnd;
}
@Override /* ContextBuilder */
@@ -91,15 +97,23 @@ public class UonParserBuilder extends ReaderParserBuilder {
* String[] <jv>foo</jv> =
<jv>parser</jv>.parse(<js>"@(foo%20bar,baz%20qux)"</js>,
String[].<jk>class</jk>);
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link UonParser#UON_decoding}
- * </ul>
- *
* @return This object (for method chaining).
*/
@FluentSetter
public UonParserBuilder decoding() {
- return set(UON_decoding);
+ return decoding(true);
+ }
+
+ /**
+ * Same as {@link #decoding()} but allows you to explicitly specify the
value.
+ *
+ * @param value The value for this setting.
+ * @return This object.
+ */
+ @FluentSetter
+ public UonParserBuilder decoding(boolean value) {
+ decoding = value;
+ return this;
}
/**
@@ -122,15 +136,23 @@ public class UonParserBuilder extends ReaderParserBuilder
{
* MyBean <jv>myBean</jv> = <jv>parser</jv>.parse(in,
MyBean.<jk>class</jk>);
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link UonParser#UON_validateEnd}
- * </ul>
- *
* @return This object (for method chaining).
*/
@FluentSetter
public UonParserBuilder validateEnd() {
- return set(UON_validateEnd);
+ return validateEnd(true);
+ }
+
+ /**
+ * Same as {@link #validateEnd()} but allows you to explicitly specify
the value.
+ *
+ * @param value The value for this setting.
+ * @return This object.
+ */
+ @FluentSetter
+ public UonParserBuilder validateEnd(boolean value) {
+ validateEnd = value;
+ return this;
}
// <FluentSetters>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
index 4a0f429..1468e1c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
@@ -13,7 +13,6 @@
package org.apache.juneau.uon;
import static org.apache.juneau.internal.StringUtils.*;
-import static org.apache.juneau.uon.UonParser.*;
import java.io.*;
import java.lang.reflect.*;
@@ -56,15 +55,14 @@ public class UonParserSession extends ReaderParserSession
implements HttpPartPar
protected UonParserSession(UonParser ctx, ParserSessionArgs args) {
super(ctx, args);
this.ctx = ctx;
- SessionProperties sp = getSessionProperties();
- decoding = sp.get(UON_decoding,
boolean.class).orElse(ctx.isDecoding());
+ decoding = ctx.decoding;
}
/**
* Create a specialized parser session for parsing URL parameters.
*
* <p>
- * The main difference is that characters are never decoded, and the
{@link UonParser#UON_decoding}
+ * The main difference is that characters are never decoded, and the
{@link UonParserBuilder#decoding()}
* property is always ignored.
*
* @param ctx
@@ -832,7 +830,7 @@ public class UonParserSession extends ReaderParserSession
implements HttpPartPar
/**
* Configuration property: Decode <js>"%xx"</js> sequences.
*
- * @see UonParser#UON_decoding
+ * @see UonParserBuilder#decoding()
* @return
* <jk>true</jk> if URI encoded characters should be decoded,
<jk>false</jk> if they've already been decoded
* before being passed to this parser.
@@ -844,7 +842,7 @@ public class UonParserSession extends ReaderParserSession
implements HttpPartPar
/**
* Configuration property: Validate end.
*
- * @see UonParser#UON_validateEnd
+ * @see UonParserBuilder#validateEnd()
* @return
* <jk>true</jk> if after parsing a POJO from the input, verifies
that the remaining input in
* the stream consists of only comments or whitespace.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializer.java
index d32df52..4d4f124 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializer.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializer.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.uon;
+import static java.util.Optional.*;
+
import java.util.*;
import java.util.concurrent.*;
@@ -123,102 +125,7 @@ import org.apache.juneau.serializer.*;
public class UonSerializer extends WriterSerializer implements
HttpPartSerializer, UonMetaProvider {
//-------------------------------------------------------------------------------------------------------------------
- // Configurable properties
-
//-------------------------------------------------------------------------------------------------------------------
-
- static final String PREFIX = "UonSerializer";
-
- /**
- * Configuration property: Add <js>"_type"</js> properties when needed.
- *
- * <h5 class='section'>Description:</h5>
- * <p>
- * If <jk>true</jk>, then <js>"_type"</js> properties will be added to
beans if their type cannot be inferred
- * through reflection.
- *
- * <p>
- * When present, this value overrides the {@link
#SERIALIZER_addBeanTypes} setting and is
- * provided to customize the behavior of specific serializers in a
{@link SerializerGroup}.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.uon.UonSerializer#UON_addBeanTypes UON_addBeanTypes}
- * <li><b>Name:</b> <js>"UonSerializer.addBeanTypes.b"</js>
- * <li><b>Data type:</b> <jk>boolean</jk>
- * <li><b>System property:</b> <c>UonSerializer.addBeanTypes</c>
- * <li><b>Environment variable:</b>
<c>UONSERIALIZER_ADDBEANTYPES</c>
- * <li><b>Default:</b> <jk>false</jk>
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.uon.annotation.UonConfig#addBeanTypes()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.uon.UonSerializerBuilder#addBeanTypes()}
- * </ul>
- * </ul>
- */
- public static final String UON_addBeanTypes = PREFIX +
".addBeanTypes.b";
-
- /**
- * Configuration property: Encode non-valid URI characters.
- *
- * <p>
- * Encode non-valid URI characters with <js>"%xx"</js> constructs.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.uon.UonSerializer#UON_encoding UON_encoding}
- * <li><b>Name:</b> <js>"UonSerializer.encoding.b"</js>
- * <li><b>Data type:</b> <jk>boolean</jk>
- * <li><b>System property:</b> <c>UonSerializer.encoding</c>
- * <li><b>Environment variable:</b> <c>UONSERIALIZER_ENCODING</c>
- * <li><b>Default:</b> <jk>false</jk> for {@link
org.apache.juneau.uon.UonSerializer}, <jk>true</jk> for {@link
org.apache.juneau.urlencoding.UrlEncodingSerializer}
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.uon.annotation.UonConfig#encoding()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.uon.UonSerializerBuilder#encoding()}
- * </ul>
- * </ul>
- */
- public static final String UON_encoding = PREFIX + ".encoding.b";
-
- /**
- * Configuration property: Format to use for query/form-data/header
values.
- *
- * <p>
- * Specifies the format to use for URL GET parameter keys and values.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.uon.UonSerializer#UON_paramFormat UON_paramFormat}
- * <li><b>Name:</b> <js>"UonSerializer.paramFormat.s"</js>
- * <li><b>Data type:</b> {@link org.apache.juneau.uon.ParamFormat}
- * <li><b>System property:</b> <c>UonSerializer.paramFormat</c>
- * <li><b>Environment variable:</b>
<c>UONSERIALIZER_PARAMFORMAT</c>
- * <li><b>Default:</b> <js>"UON"</js>
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.uon.annotation.UonConfig#paramFormat()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.uon.UonSerializerBuilder#paramFormat(ParamFormat)}
- * <li class='jm'>{@link
org.apache.juneau.uon.UonSerializerBuilder#paramFormatPlain()}
- * </ul>
- * </ul>
- */
- public static final String UON_paramFormat = PREFIX + ".paramFormat.s";
-
-
-
//-------------------------------------------------------------------------------------------------------------------
- // Predefined instances
+ // Static
//-------------------------------------------------------------------------------------------------------------------
/** Reusable instance of {@link UonSerializer}, all default settings. */
@@ -230,9 +137,8 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
/** Reusable instance of {@link UonSerializer.Encoding}. */
public static final UonSerializer DEFAULT_ENCODING = new
Encoding(create());
-
//-------------------------------------------------------------------------------------------------------------------
- // Predefined subclasses
+ // Static subclasses
//-------------------------------------------------------------------------------------------------------------------
/**
@@ -290,15 +196,16 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
// Instance
//-------------------------------------------------------------------------------------------------------------------
- private final boolean
+ final boolean
encoding,
- addBeanTypes;
-
- private final char
- quoteChar;
-
- private final ParamFormat
+ addBeanTypesUon;
+ final ParamFormat
paramFormat;
+ final Character
+ quoteCharUon;
+
+ private final boolean addBeanTypes;
+ private final char quoteChar;
private final Map<ClassMeta<?>,UonClassMeta> uonClassMetas = new
ConcurrentHashMap<>();
private final Map<BeanPropertyMeta,UonBeanPropertyMeta>
uonBeanPropertyMetas = new ConcurrentHashMap<>();
@@ -311,11 +218,14 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
*/
protected UonSerializer(UonSerializerBuilder builder) {
super(builder);
- ContextProperties cp = getContextProperties();
- encoding = cp.getBoolean(UON_encoding).orElse(false);
- addBeanTypes = cp.getFirstBoolean(UON_addBeanTypes,
SERIALIZER_addBeanTypes).orElse(false);
- paramFormat = cp.get(UON_paramFormat,
ParamFormat.class).orElse(ParamFormat.UON);
- quoteChar =
cp.getString(WSERIALIZER_quoteCharOverride).orElse(cp.getString(WSERIALIZER_quoteChar).orElse("'")).charAt(0);
+
+ encoding = builder.encoding;
+ addBeanTypesUon = builder.addBeanTypesUon;
+ paramFormat = builder.paramFormat;
+ quoteCharUon = builder.quoteCharUon;
+
+ addBeanTypes = addBeanTypesUon || super.isAddBeanTypes();
+ quoteChar =
ofNullable(quoteCharUon).orElse(ofNullable(super.quoteChar()).orElse('\''));
}
@Override /* Context */
@@ -392,7 +302,7 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
/**
* Add <js>"_type"</js> properties when needed.
*
- * @see #UON_addBeanTypes
+ * @see UonSerializerBuilder#addBeanTypesUon()
* @return
* <jk>true</jk> if <js>"_type"</js> properties will be added to
beans if their type cannot be inferred
* through reflection.
@@ -405,7 +315,7 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
/**
* Encode non-valid URI characters.
*
- * @see #UON_encoding
+ * @see UonSerializerBuilder#encoding()
* @return
* <jk>true</jk> if non-valid URI characters should be encoded
with <js>"%xx"</js> constructs.
*/
@@ -416,7 +326,7 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
/**
* Format to use for query/form-data/header values.
*
- * @see #UON_paramFormat
+ * @see UonSerializerBuilder#paramFormat(ParamFormat)
* @return
* Specifies the format to use for URL GET parameter keys and
values.
*/
@@ -427,7 +337,7 @@ public class UonSerializer extends WriterSerializer
implements HttpPartSerialize
/**
* Quote character.
*
- * @see WriterSerializer#WSERIALIZER_quoteChar
+ * @see UonSerializerBuilder#quoteCharUon(char)
* @return
* The character used for quoting attributes and values.
*/
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerBuilder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerBuilder.java
index 9465935..56b076c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerBuilder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerBuilder.java
@@ -12,8 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau.uon;
-import static org.apache.juneau.uon.UonSerializer.*;
-
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.nio.charset.*;
@@ -31,6 +29,10 @@ import org.apache.juneau.serializer.*;
@FluentSetters
public class UonSerializerBuilder extends WriterSerializerBuilder {
+ boolean addBeanTypesUon, encoding;
+ ParamFormat paramFormat;
+ Character quoteCharUon;
+
/**
* Constructor, default settings.
*/
@@ -38,6 +40,10 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
super();
produces("text/uon");
type(UonSerializer.class);
+ addBeanTypesUon = env("UonSerializer.addBeanTypesUon", false);
+ encoding = env("UonSerializer.encoding", false);
+ paramFormat = env("UonSerializer.paramFormat", ParamFormat.UON);
+ quoteCharUon = null;
}
/**
@@ -47,6 +53,10 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
*/
protected UonSerializerBuilder(UonSerializer copyFrom) {
super(copyFrom);
+ addBeanTypesUon = copyFrom.addBeanTypesUon;
+ encoding = copyFrom.encoding;
+ paramFormat = copyFrom.paramFormat;
+ quoteCharUon = copyFrom.quoteCharUon;
}
/**
@@ -56,6 +66,10 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
*/
protected UonSerializerBuilder(UonSerializerBuilder copyFrom) {
super(copyFrom);
+ addBeanTypesUon = copyFrom.addBeanTypesUon;
+ encoding = copyFrom.encoding;
+ paramFormat = copyFrom.paramFormat;
+ quoteCharUon = copyFrom.quoteCharUon;
}
@Override /* ContextBuilder */
@@ -73,6 +87,36 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
//-----------------------------------------------------------------------------------------------------------------
/**
+ * Add <js>"_type"</js> properties when needed.
+ *
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to
beans if their type cannot be inferred
+ * through reflection.
+ *
+ * <p>
+ * When present, this value overrides the {@link
SerializerBuilder#addBeanTypes()} setting and is
+ * provided to customize the behavior of specific serializers in a
{@link SerializerGroup}.
+ *
+ * @return This object.
+ */
+ @FluentSetter
+ public UonSerializerBuilder addBeanTypesUon() {
+ return addBeanTypesUon(true);
+ }
+
+ /**
+ * Same as {@link #addBeanTypesUon()} but allows you to explicitly
specify the value.
+ *
+ * @param value The value for this setting.
+ * @return This object.
+ */
+ @FluentSetter
+ public UonSerializerBuilder addBeanTypesUon(boolean value) {
+ addBeanTypesUon = value;
+ return this;
+ }
+
+ /**
* Encode non-valid URI characters.
*
* <p>
@@ -105,15 +149,11 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
* String <jv>uon2</jv> =
<jv>serializer2</jv>.serialize(<jv>myMap</jv>)
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_encoding}
- * </ul>
- *
* @return This object (for method chaining).
*/
@FluentSetter
public UonSerializerBuilder encoding() {
- return set(UON_encoding);
+ return encoding(true);
}
/**
@@ -123,7 +163,8 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
* @return This object.
*/
public UonSerializerBuilder encoding(boolean value) {
- return set(UON_encoding, value);
+ encoding = value;
+ return this;
}
/**
@@ -164,10 +205,6 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
* String <jv>uon2</jv> =
<jv>serializer2</jv>.serialize(<jv>myMap</jv>)
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_paramFormat}
- * </ul>
- *
* @param value
* The new value for this property.
* <br>The default value is {@link ParamFormat#UON}.
@@ -175,7 +212,8 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
*/
@FluentSetter
public UonSerializerBuilder paramFormat(ParamFormat value) {
- return set(UON_paramFormat, value);
+ paramFormat = value;
+ return this;
}
/**
@@ -201,15 +239,23 @@ public class UonSerializerBuilder extends
WriterSerializerBuilder {
* String <jv>uon</jv> =
<jv>serializer</jv>.serialize(<jv>myMap</jv>)
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_paramFormat}
- * </ul>
- *
* @return This object (for method chaining).
*/
@FluentSetter
public UonSerializerBuilder paramFormatPlain() {
- return set(UON_paramFormat, ParamFormat.PLAINTEXT);
+ return paramFormat(ParamFormat.PLAINTEXT);
+ }
+
+ /**
+ * Specifies the quote character.
+ *
+ * @param value The value for this setting.
+ * @return This object.
+ */
+ @FluentSetter
+ public UonSerializerBuilder quoteCharUon(char value) {
+ quoteCharUon = value;
+ return this;
}
// <FluentSetters>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
index 3b8ec45..e57fda2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
@@ -41,7 +41,7 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
* @param ctx
* The context creating this session object.
* The context contains all the configuration settings for this
object.
- * @param encode Override the {@link UonSerializer#UON_encoding}
setting.
+ * @param encode Override the {@link UonSerializerBuilder#encoding()}
setting.
* @param args
* Runtime arguments.
* These specify session-level information such as locale and URI
context.
@@ -304,7 +304,7 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
/**
* Configuration property: Add <js>"_type"</js> properties when needed.
*
- * @see UonSerializer#UON_addBeanTypes
+ * @see UonSerializerBuilder#addBeanTypesUon()
* @return
* <jk>true</jk> if <js>"_type"</js> properties will be added to
beans if their type cannot be inferred
* through reflection.
@@ -317,7 +317,7 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
/**
* Configuration property: Encode non-valid URI characters.
*
- * @see UonSerializer#UON_encoding
+ * @see UonSerializerBuilder#encoding()
* @return
* <jk>true</jk> if non-valid URI characters should be encoded
with <js>"%xx"</js> constructs.
*/
@@ -328,7 +328,7 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
/**
* Configuration property: Format to use for query/form-data/header
values.
*
- * @see UonSerializer#UON_paramFormat
+ * @see UonSerializerBuilder#paramFormat(ParamFormat)
* @return
* Specifies the format to use for URL GET parameter keys and
values.
*/
@@ -339,7 +339,7 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
/**
* Configuration property: Quote character.
*
- * @see WriterSerializer#WSERIALIZER_quoteChar
+ * @see UonSerializerBuilder#quoteCharUon(char)
* @return
* The character used for quoting attributes and values.
*/
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfig.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfig.java
index 38db5ca..be6cfac 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfig.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfig.java
@@ -32,7 +32,7 @@ import org.apache.juneau.urlencoding.*;
@Target({TYPE,METHOD})
@Retention(RUNTIME)
@Inherited
-@ContextApply(UonConfigAnnotation.Apply.class)
+@ContextApply({UonConfigAnnotation.SerializerApply.class,UonConfigAnnotation.ParserApply.class})
public @interface UonConfig {
/**
@@ -72,7 +72,7 @@ public @interface UonConfig {
* </ul>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonParser#UON_decoding}
+ * <li class='jm'>{@link UonParserBuilder#decoding()}
* </ul>
*/
String decoding() default "";
@@ -96,7 +96,7 @@ public @interface UonConfig {
* </ul>
* <ul class='seealso'>
- * <li class='jf'>{@link UonParser#UON_validateEnd}
+ * <li class='jm'>{@link UonParserBuilder#validateEnd()}
* </ul>
*/
String validateEnd() default "";
@@ -128,7 +128,7 @@ public @interface UonConfig {
* </ul>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_addBeanTypes}
+ * <li class='jm'>{@link UonSerializerBuilder#addBeanTypesUon()}
* </ul>
*/
String addBeanTypes() default "";
@@ -165,7 +165,7 @@ public @interface UonConfig {
* </ul>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_encoding}
+ * <li class='jm'>{@link UonSerializerBuilder#encoding()}
* </ul>
*/
String encoding() default "";
@@ -188,7 +188,7 @@ public @interface UonConfig {
* </ul>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_paramFormat}
+ * <li class='jm'>{@link
UonSerializerBuilder#paramFormat(ParamFormat)}
* </ul>
*/
String paramFormat() default "";
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfigAnnotation.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfigAnnotation.java
index e937f04..2b6e65a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfigAnnotation.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/annotation/UonConfigAnnotation.java
@@ -12,12 +12,10 @@
//
***************************************************************************************************************************
package org.apache.juneau.uon.annotation;
-import static org.apache.juneau.uon.UonParser.*;
-import static org.apache.juneau.uon.UonSerializer.*;
-
import org.apache.juneau.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.svl.*;
+import org.apache.juneau.uon.*;
/**
* Utility classes and methods for the {@link UonConfig @UonConfig} annotation.
@@ -25,28 +23,49 @@ import org.apache.juneau.svl.*;
public class UonConfigAnnotation {
/**
- * Applies {@link UonConfig} annotations to a {@link
ContextPropertiesBuilder}.
+ * Applies {@link UonConfig} annotations to a {@link
UonSerializerBuilder}.
+ */
+ public static class SerializerApply extends
AnnotationApplier<UonConfig,UonSerializerBuilder> {
+
+ /**
+ * Constructor.
+ *
+ * @param vr The resolver for resolving values in annotations.
+ */
+ public SerializerApply(VarResolverSession vr) {
+ super(UonConfig.class, UonSerializerBuilder.class, vr);
+ }
+
+ @Override
+ public void apply(AnnotationInfo<UonConfig> ai,
UonSerializerBuilder b) {
+ UonConfig a = ai.getAnnotation();
+
+ bool(a.addBeanTypes()).ifPresent(x ->
b.addBeanTypesUon(x));
+ bool(a.encoding()).ifPresent(x -> b.encoding(x));
+
string(a.paramFormat()).map(ParamFormat::valueOf).ifPresent(x ->
b.paramFormat(x));
+ }
+ }
+
+ /**
+ * Applies {@link UonConfig} annotations to a {@link UonParserBuilder}.
*/
- public static class Apply extends
AnnotationApplier<UonConfig,ContextPropertiesBuilder> {
+ public static class ParserApply extends
AnnotationApplier<UonConfig,UonParserBuilder> {
/**
* Constructor.
*
* @param vr The resolver for resolving values in annotations.
*/
- public Apply(VarResolverSession vr) {
- super(UonConfig.class, ContextPropertiesBuilder.class,
vr);
+ public ParserApply(VarResolverSession vr) {
+ super(UonConfig.class, UonParserBuilder.class, vr);
}
@Override
- public void apply(AnnotationInfo<UonConfig> ai,
ContextPropertiesBuilder b) {
+ public void apply(AnnotationInfo<UonConfig> ai,
UonParserBuilder b) {
UonConfig a = ai.getAnnotation();
- bool(a.addBeanTypes()).ifPresent(x ->
b.set(UON_addBeanTypes, x));
- bool(a.encoding()).ifPresent(x -> b.set(UON_encoding,
x));
- string(a.paramFormat()).ifPresent(x ->
b.set(UON_paramFormat, x));
- bool(a.decoding()).ifPresent(x -> b.set(UON_decoding,
x));
- bool(a.validateEnd()).ifPresent(x ->
b.set(UON_validateEnd, x));
+ bool(a.decoding()).ifPresent(x -> b.decoding(x));
+ bool(a.validateEnd()).ifPresent(x -> b.validateEnd(x));
}
}
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
index a13e487..a86acd7 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
@@ -43,7 +43,7 @@ public class UrlEncodingSerializerSession extends
UonSerializerSession {
* @param ctx
* The context creating this session object.
* The context contains all the configuration settings for this
object.
- * @param encode Override the {@link UonSerializer#UON_encoding}
setting.
+ * @param encode Override the {@link UonSerializerBuilder#encoding()}
setting.
* @param args
* Runtime arguments.
* These specify session-level information such as locale and URI
context.
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
index 5cfff8c..a7b826e 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
@@ -4698,7 +4698,7 @@ public class RestClientBuilder extends
BeanContextableBuilder {
* </p>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_paramFormat}
+ * <li class='jm'>{@link
UonSerializerBuilder#paramFormat(ParamFormat)}
* </ul>
*
* @param value The new value for this property.
@@ -4740,7 +4740,7 @@ public class RestClientBuilder extends
BeanContextableBuilder {
* </p>
*
* <ul class='seealso'>
- * <li class='jf'>{@link UonSerializer#UON_paramFormat}
+ * <li class='jm'>{@link UonSerializerBuilder#paramFormatPlain()}
* </ul>
*
* @return This object (for method chaining).