juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [juneau] branch master updated: Serializer API cleanup.
Date Mon, 09 Jul 2018 00:16:48 GMT
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 5dac962  Serializer API cleanup.
5dac962 is described below

commit 5dac962223056ce1dd95390c4e840f6e7865235b
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Sun Jul 8 20:16:33 2018 -0400

    Serializer API cleanup.
---
 .../apache/juneau/msgpack/MsgPackSerializer.java   | 11 +++++-
 .../juneau/msgpack/MsgPackSerializerSession.java   | 27 ++++++-------
 .../juneau/serializer/OutputStreamSerializer.java  | 17 +++++++-
 .../serializer/OutputStreamSerializerSession.java  | 22 +++++++++--
 .../org/apache/juneau/serializer/Serializer.java   |  2 +-
 .../apache/juneau/serializer/WriterSerializer.java | 43 ++++++++++++++++++--
 .../juneau/serializer/WriterSerializerSession.java | 46 +++++++++++-----------
 .../xmlschema/XmlSchemaSerializerSession.java      | 15 -------
 .../juneau/examples/rest/RootContentTest.java      | 10 ++---
 9 files changed, 125 insertions(+), 68 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java
index 36d9a67..4407d3a 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java
@@ -110,7 +110,7 @@ public class MsgPackSerializer extends OutputStreamSerializer {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final boolean
+	private final boolean
 		addBeanTypes;
 
 	/**
@@ -149,6 +149,15 @@ public class MsgPackSerializer extends OutputStreamSerializer {
 		return new MsgPackSerializerSession(this, args);
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	@Override
+	protected final boolean isAddBeanTypes() {
+		return addBeanTypes;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
index 7196421..15bc2d8 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
@@ -12,8 +12,6 @@
 // ***************************************************************************************************************************
 package org.apache.juneau.msgpack;
 
-import static org.apache.juneau.msgpack.MsgPackSerializer.*;
-
 import java.util.*;
 
 import org.apache.juneau.*;
@@ -30,8 +28,7 @@ import org.apache.juneau.transform.*;
  */
 public final class MsgPackSerializerSession extends OutputStreamSerializerSession {
 
-	private final boolean
-		addBeanTypes;
+	private final MsgPackSerializer ctx;
 
 	/**
 	 * Create a new session using properties specified in the context.
@@ -47,27 +44,16 @@ public final class MsgPackSerializerSession extends OutputStreamSerializerSessio
 	 */
 	protected MsgPackSerializerSession(MsgPackSerializer ctx, SerializerSessionArgs args) {
 		super(ctx, args);
-		addBeanTypes = getProperty(MSGPACK_addBeanTypes, boolean.class, ctx.addBeanTypes);
+		this.ctx = ctx;
 	}
 
 	@Override /* Session */
 	public ObjectMap asMap() {
 		return super.asMap()
 			.append("MsgPackSerializerSession", new ObjectMap()
-				.append("addBeanTypes", addBeanTypes)
 			);
 	}
 
-	/**
-	 * Returns the {@link MsgPackSerializer#MSGPACK_addBeanTypes} setting value for this session.
-	 *
-	 * @return The {@link MsgPackSerializer#MSGPACK_addBeanTypes} setting value for this session.
-	 */
-	@Override /* SerializerSession */
-	protected final boolean isAddBeanTypes() {
-		return addBeanTypes;
-	}
-
 	@Override /* SerializerSession */
 	protected void doSerialize(SerializerPipe out, Object o) throws Exception {
 		serializeAnything(getMsgPackOutputStream(out), o, getExpectedRootType(o), "root", null);
@@ -234,4 +220,13 @@ public final class MsgPackSerializerSession extends OutputStreamSerializerSessio
 		for (Object o : l)
 			serializeAnything(out, o, elementType, "<iterator>", null);
 	}
+
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	@Override
+	protected final boolean isAddBeanTypes() {
+		return ctx.isAddBeanTypes();
+	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializer.java
index 21fda75..683f5d5 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializer.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializer.java
@@ -80,7 +80,7 @@ public abstract class OutputStreamSerializer extends Serializer {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final BinaryFormat binaryFormat;
+	private final BinaryFormat binaryFormat;
 
 	/**
 	 * Constructor.
@@ -145,6 +145,21 @@ public abstract class OutputStreamSerializer extends Serializer {
 		return createSession(createDefaultSessionArgs()).serialize(o);
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Binary output format.
+	 *
+	 * @see #OSSERIALIZER_binaryFormat
+	 * @return
+	 * 	The format to use for the {@link #serializeToString(Object)} method on stream-based
serializers when converting byte arrays to strings.
+	 */
+	protected final BinaryFormat getBinaryFormat() {
+		return binaryFormat;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializerSession.java
index 8e77697..18e95e6 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/OutputStreamSerializerSession.java
@@ -32,7 +32,7 @@ import org.apache.juneau.internal.*;
  */
 public abstract class OutputStreamSerializerSession extends SerializerSession {
 
-	private final BinaryFormat binaryFormat;
+	private final OutputStreamSerializer ctx;
 
 	/**
 	 * Create a new session using properties specified in the context.
@@ -48,8 +48,7 @@ public abstract class OutputStreamSerializerSession extends SerializerSession
{
 	 */
 	protected OutputStreamSerializerSession(OutputStreamSerializer ctx, SerializerSessionArgs
args) {
 		super(ctx, args);
-
-		binaryFormat = getProperty(OSSERIALIZER_binaryFormat, BinaryFormat.class, ctx.binaryFormat);
+		this.ctx = ctx;
 	}
 
 	/**
@@ -84,11 +83,26 @@ public abstract class OutputStreamSerializerSession extends SerializerSession
{
 	@Override /* SerializerSession */
 	public final String serializeToString(Object o) throws SerializeException {
 		byte[] b = serialize(o);
-		switch(binaryFormat) {
+		switch(getBinaryFormat()) {
 			case SPACED_HEX:  return StringUtils.toSpacedHex(b);
 			case HEX:  return StringUtils.toHex(b);
 			case BASE64:  return StringUtils.base64Encode(b);
 			default: return null;
 		}
 	}
+
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Binary output format.
+	 *
+	 * @see #OSSERIALIZER_binaryFormat
+	 * @return
+	 * 	The format to use for the {@link #serializeToString(Object)} method on stream-based
serializers when converting byte arrays to strings.
+	 */
+	protected final BinaryFormat getBinaryFormat() {
+		return ctx.getBinaryFormat();
+	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
index 9396588..9891917 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
@@ -1137,7 +1137,7 @@ public abstract class Serializer extends BeanContext {
 	 * 	<jk>true</jk> if <js>"_type"</js> properties added to beans
if their type cannot be inferred
 	 * 	through reflection.
 	 */
-	protected final boolean isAddBeanTypes() {
+	protected boolean isAddBeanTypes() {
 		return addBeanTypes;
 	}
 
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 3a6d688..b7b4786 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
@@ -157,9 +157,9 @@ public abstract class WriterSerializer extends Serializer {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final int maxIndent;
-	final boolean useWhitespace;
-	final char quoteChar;
+	private final int maxIndent;
+	private final boolean useWhitespace;
+	private final char quoteChar;
 
 	/**
 	 * Constructor.
@@ -264,6 +264,43 @@ public abstract class WriterSerializer extends Serializer {
 		return this;
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Maximum indentation.
+	 *
+	 * @see #WSERIALIZER_maxIndent
+	 * @return
+	 * 	The maximum indentation level in the serialized document.
+	 */
+	protected final int getMaxIndent() {
+		return maxIndent;
+	}
+
+	/**
+	 * Configuration property:  Use whitespace.
+	 *
+	 * @see #WSERIALIZER_useWhitespace
+	 * @return
+	 * 	<jk>true</jk> if whitespace is added to the output to improve readability.
+	 */
+	protected final boolean isUseWhitespace() {
+		return useWhitespace;
+	}
+
+	/**
+	 * Configuration property:  Quote character.
+	 *
+	 * @see #WSERIALIZER_quoteChar
+	 * @return
+	 * 	The character used for quoting attributes and values.
+	 */
+	protected final char getQuoteChar() {
+		return quoteChar;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializerSession.java
index 9ce6850..f66dbc7 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/WriterSerializerSession.java
@@ -36,9 +36,7 @@ import org.apache.juneau.*;
  */
 public abstract class WriterSerializerSession extends SerializerSession {
 
-	private final int maxIndent;
-	private final boolean useWhitespace;
-	private final char quoteChar;
+	private final WriterSerializer ctx;
 
 	/**
 	 * Create a new session using properties specified in the context.
@@ -54,10 +52,7 @@ public abstract class WriterSerializerSession extends SerializerSession
{
 	 */
 	protected WriterSerializerSession(WriterSerializer ctx, SerializerSessionArgs args) {
 		super(ctx, args);
-
-		useWhitespace = getProperty(WSERIALIZER_useWhitespace, boolean.class, ctx.useWhitespace);
-		maxIndent = getProperty(WSERIALIZER_maxIndent, int.class, ctx.maxIndent);
-		quoteChar = getProperty(WSERIALIZER_quoteChar, String.class, ""+ctx.quoteChar).charAt(0);
+		this.ctx = ctx;
 	}
 
 	/**
@@ -94,40 +89,47 @@ public abstract class WriterSerializerSession extends SerializerSession
{
 		return serialize(o);
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
 	/**
-	 * Returns the {@link WriterSerializer#WSERIALIZER_useWhitespace} setting value for this
session.
+	 * Configuration property:  Maximum indentation.
 	 *
-	 * @return The {@link WriterSerializer#WSERIALIZER_useWhitespace} setting value for this
session.
+	 * @see #WSERIALIZER_maxIndent
+	 * @return
+	 * 	The maximum indentation level in the serialized document.
 	 */
-	protected boolean isUseWhitespace() {
-		return useWhitespace;
+	public final int getMaxIndent() {
+		return ctx.getMaxIndent();
 	}
 
 	/**
-	 * Returns the {@link WriterSerializer#WSERIALIZER_maxIndent} setting value for this session.
+	 * Configuration property:  Use whitespace.
 	 *
-	 * @return The {@link WriterSerializer#WSERIALIZER_maxIndent} setting value for this session.
+	 * @see #WSERIALIZER_useWhitespace
+	 * @return
+	 * 	<jk>true</jk> if whitespace is added to the output to improve readability.
 	 */
-	protected int getMaxIndent() {
-		return maxIndent;
+	public final boolean isUseWhitespace() {
+		return ctx.isUseWhitespace();
 	}
 
 	/**
-	 * Returns the {@link WriterSerializer#WSERIALIZER_quoteChar} setting value for this session.
+	 * Configuration property:  Quote character.
 	 *
-	 * @return The {@link WriterSerializer#WSERIALIZER_quoteChar} setting value for this session.
+	 * @see #WSERIALIZER_quoteChar
+	 * @return
+	 * 	The character used for quoting attributes and values.
 	 */
-	protected char getQuoteChar() {
-		return quoteChar;
+	public final char getQuoteChar() {
+		return ctx.getQuoteChar();
 	}
 
 	@Override /* Session */
 	public ObjectMap asMap() {
 		return super.asMap()
 			.append("WriterSerializerSession", new ObjectMap()
-				.append("maxIndent", maxIndent)
-				.append("useWhitespace", useWhitespace)
-				.append("quoteChar", quoteChar)
 			);
 	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xmlschema/XmlSchemaSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xmlschema/XmlSchemaSerializerSession.java
index e1a6657..45f8a96 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xmlschema/XmlSchemaSerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xmlschema/XmlSchemaSerializerSession.java
@@ -226,25 +226,10 @@ public class XmlSchemaSerializerSession extends XmlSerializerSession
{
 	}
 
 	@Override /* SerializerSession */
-	protected boolean isUseWhitespace() {
-		return super.isUseWhitespace();
-	}
-
-	@Override /* SerializerSession */
-	protected int getMaxIndent() {
-		return super.getMaxIndent();
-	}
-
-	@Override /* SerializerSession */
 	protected boolean isTrimStrings() {
 		return super.isTrimStrings();
 	}
 
-	@Override /* SerializerSession */
-	protected char getQuoteChar() {
-		return super.getQuoteChar();
-	}
-
 	/* An encapsulation of a single schema. */
 	private final class Schema {
 		private StringWriter sw = new StringWriter();
diff --git a/juneau-examples/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootContentTest.java
b/juneau-examples/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootContentTest.java
index 8d5f69e..0125f47 100644
--- a/juneau-examples/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootContentTest.java
+++ b/juneau-examples/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootContentTest.java
@@ -55,15 +55,15 @@ public class RootContentTest extends ContentComboTestBase {
 			{ 	/* 4 */
 				new ComboInput("HTML-nav-popup-contentType", "/", MediaType.HTML,
 					"<div class='popup-content'>",
-					"<a href='/?plainText=true&Accept=application%2Fjson'>application/json</a>"
+					"/?plainText=true&Accept=application%2Fjson"
 				)
 			},
 			{ 	/* 5 */
 				new ComboInput("HTML-nav-popup-styles", "/", MediaType.HTML,
-					"<a href='/?stylesheet=htdocs%2Fthemes%2Fdevops.css'>devops</a>",
-					"<a href='/?stylesheet=htdocs%2Fthemes%2Flight.css'>light</a>",
-					"<a href='/?stylesheet=htdocs%2Fthemes%2Foriginal.css'>original</a>",
-					"<a href='/?stylesheet=htdocs%2Fthemes%2Fdark.css'>dark</a>"
+					"/?stylesheet=htdocs%2Fthemes%2Fdevops.css",
+					"/?stylesheet=htdocs%2Fthemes%2Flight.css",
+					"/?stylesheet=htdocs%2Fthemes%2Foriginal.css",
+					"/?stylesheet=htdocs%2Fthemes%2Fdark.css"
 				)
 			},
 			{ 	/* 6 */


Mime
View raw message