You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/02/16 21:31:40 UTC
incubator-juneau git commit: Add addBeanTypeProperties settings for
individual serializers.
Repository: incubator-juneau
Updated Branches:
refs/heads/master 9dc9b7515 -> 949921157
Add addBeanTypeProperties settings for individual serializers.
Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/94992115
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/94992115
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/94992115
Branch: refs/heads/master
Commit: 94992115738f8b55ae104556ebd08e91feb56847
Parents: 9dc9b75
Author: JamesBognar <ja...@apache.org>
Authored: Thu Feb 16 16:30:29 2017 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Thu Feb 16 16:31:37 2017 -0500
----------------------------------------------------------------------
.../juneau/jena/RdfSerializerContext.java | 29 ++++++++++++++++-
.../juneau/jena/RdfSerializerSession.java | 21 ++++++++++++-
.../juneau/html/HtmlSerializerContext.java | 29 ++++++++++++++++-
.../juneau/html/HtmlSerializerSession.java | 18 ++++++++++-
.../juneau/json/JsonSerializerContext.java | 23 +++++++++++++-
.../juneau/json/JsonSerializerSession.java | 17 +++++++++-
.../msgpack/MsgPackSerializerContext.java | 24 ++++++++++++++
.../msgpack/MsgPackSerializerSession.java | 22 ++++++++++++-
.../juneau/serializer/SerializerSession.java | 4 +--
.../urlencoding/UonSerializerContext.java | 24 +++++++++++++-
.../urlencoding/UonSerializerSession.java | 33 ++++++++++++++------
.../juneau/urlencoding/doc-files/rfc_uon.txt | 28 ++++++++---------
.../apache/juneau/xml/XmlSerializerContext.java | 24 +++++++++++++-
.../apache/juneau/xml/XmlSerializerSession.java | 16 +++++++++-
juneau-core/src/main/javadoc/overview.html | 26 +++++++++++++++
15 files changed, 303 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java
index 7dcd923..8c91057 100644
--- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java
+++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java
@@ -103,8 +103,33 @@ public final class RdfSerializerContext extends SerializerContext implements Rdf
*/
public static final String RDF_namespaces = "RdfSerializer.namespaces.list";
+ /**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"RdfSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String RDF_addBeanTypeProperties = "RdfSerializer.addBeanTypeProperties";
+
- final boolean addLiteralTypes, addRootProperty, useXmlNamespaces, looseCollections, autoDetectNamespaces;
+ final boolean
+ addLiteralTypes,
+ addRootProperty,
+ useXmlNamespaces,
+ looseCollections,
+ autoDetectNamespaces,
+ addBeanTypeProperties;
final String rdfLanguage;
final Namespace juneauNs;
final Namespace juneauBpNs;
@@ -131,6 +156,7 @@ public final class RdfSerializerContext extends SerializerContext implements Rdf
juneauBpNs = cf.getProperty(RDF_juneauBpNs, Namespace.class, new Namespace("jp", "http://www.apache.org/juneaubp/"));
collectionFormat = cf.getProperty(RDF_collectionFormat, RdfCollectionFormat.class, RdfCollectionFormat.DEFAULT);
namespaces = cf.getProperty(RDF_namespaces, Namespace[].class, new Namespace[0]);
+ addBeanTypeProperties = cf.getProperty(RDF_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
@@ -147,6 +173,7 @@ public final class RdfSerializerContext extends SerializerContext implements Rdf
.append("juneauBpNs", juneauBpNs)
.append("collectionFormat", collectionFormat)
.append("namespaces", namespaces)
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
index d03b775..ef9f347 100644
--- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
+++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java
@@ -21,6 +21,7 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.json.*;
+import org.apache.juneau.msgpack.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.xml.*;
@@ -35,7 +36,13 @@ public final class RdfSerializerSession extends SerializerSession {
private final String rdfLanguage;
private final Namespace juneauNs, juneauBpNs;
- private final boolean addLiteralTypes, addRootProperty, useXmlNamespaces, looseCollections, autoDetectNamespaces;
+ private final boolean
+ addLiteralTypes,
+ addRootProperty,
+ useXmlNamespaces,
+ looseCollections,
+ autoDetectNamespaces,
+ addBeanTypeProperties;
private final Property pRoot, pValue, pType;
private final Model model;
private final RDFWriter writer;
@@ -74,6 +81,7 @@ public final class RdfSerializerSession extends SerializerSession {
this.useXmlNamespaces = ctx.useXmlNamespaces;
this.autoDetectNamespaces = ctx.autoDetectNamespaces;
this.namespaces = ctx.namespaces;
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
} else {
this.rdfLanguage = op.getString(RDF_language, ctx.rdfLanguage);
this.juneauNs = (op.containsKey(RDF_juneauNs) ? NamespaceFactory.parseNamespace(op.get(RDF_juneauNs)) : ctx.juneauNs);
@@ -90,6 +98,7 @@ public final class RdfSerializerSession extends SerializerSession {
this.useXmlNamespaces = op.getBoolean(RDF_useXmlNamespaces, ctx.useXmlNamespaces);
this.autoDetectNamespaces = op.getBoolean(RDF_autoDetectNamespaces, ctx.autoDetectNamespaces);
this.namespaces = op.get(Namespace[].class, RDF_namespaces, ctx.namespaces);
+ addBeanTypeProperties = op.getBoolean(RDF_addBeanTypeProperties, ctx.addBeanTypeProperties);
}
this.model = ModelFactory.createDefaultModel();
addModelPrefix(juneauNs);
@@ -202,6 +211,16 @@ public final class RdfSerializerSession extends SerializerSession {
}
/**
+ * Returns the {@link MsgPackSerializerContext#MSGPACK_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link MsgPackSerializerContext#MSGPACK_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public final boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
+ }
+
+ /**
* Returns the RDF property that identifies the root node in the RDF model.
*
* @return The RDF property that identifies the root node in the RDF model.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerContext.java
index b15271a..b2096c1 100644
--- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerContext.java
@@ -13,6 +13,7 @@
package org.apache.juneau.html;
import org.apache.juneau.*;
+import org.apache.juneau.serializer.*;
import org.apache.juneau.xml.*;
/**
@@ -126,8 +127,32 @@ public class HtmlSerializerContext extends XmlSerializerContext {
*/
public static final String HTML_addKeyValueTableHeaders = "HtmlSerializer.addKeyValueTableHeaders";
+ /**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"HtmlSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String HTML_addBeanTypeProperties = "HtmlSerializer.addBeanTypeProperties";
+
+
final String uriAnchorText;
- final boolean lookForLabelParameters, detectLinksInStrings, addKeyValueTableHeaders;
+ final boolean
+ lookForLabelParameters,
+ detectLinksInStrings,
+ addKeyValueTableHeaders,
+ addBeanTypeProperties;
final String labelParameter;
/**
@@ -144,6 +169,7 @@ public class HtmlSerializerContext extends XmlSerializerContext {
detectLinksInStrings = cf.getProperty(HTML_detectLinksInStrings, Boolean.class, true);
labelParameter = cf.getProperty(HTML_labelParameter, String.class, "label");
addKeyValueTableHeaders = cf.getProperty(HTML_addKeyValueTableHeaders, Boolean.class, false);
+ addBeanTypeProperties = cf.getProperty(HTML_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
@@ -155,6 +181,7 @@ public class HtmlSerializerContext extends XmlSerializerContext {
.append("detectLinksInStrings", detectLinksInStrings)
.append("labelParameter", labelParameter)
.append("addKeyValueTableHeaders", addKeyValueTableHeaders)
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
index 3d67924..ad573c8 100644
--- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializerSession.java
@@ -13,6 +13,7 @@
package org.apache.juneau.html;
import static org.apache.juneau.html.HtmlSerializerContext.*;
+import static org.apache.juneau.msgpack.MsgPackSerializerContext.*;
import java.lang.reflect.*;
import java.util.*;
@@ -31,7 +32,11 @@ import org.apache.juneau.xml.*;
public class HtmlSerializerSession extends XmlSerializerSession {
private final AnchorText anchorText;
- private final boolean detectLinksInStrings, lookForLabelParameters, addKeyValueTableHeaders;
+ private final boolean
+ detectLinksInStrings,
+ lookForLabelParameters,
+ addKeyValueTableHeaders,
+ addBeanTypeProperties;
private final Pattern urlPattern = Pattern.compile("http[s]?\\:\\/\\/.*");
private final Pattern labelPattern;
private final String absolutePathUriBase, relativeUriBase;
@@ -66,12 +71,14 @@ public class HtmlSerializerSession extends XmlSerializerSession {
lookForLabelParameters = ctx.lookForLabelParameters;
labelParameter = ctx.labelParameter;
addKeyValueTableHeaders = ctx.addKeyValueTableHeaders;
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
} else {
anchorText = Enum.valueOf(AnchorText.class, op.getString(HTML_uriAnchorText, ctx.uriAnchorText));
detectLinksInStrings = op.getBoolean(HTML_detectLinksInStrings, ctx.detectLinksInStrings);
lookForLabelParameters = op.getBoolean(HTML_lookForLabelParameters, ctx.lookForLabelParameters);
labelParameter = op.getString(HTML_labelParameter, ctx.labelParameter);
addKeyValueTableHeaders = op.getBoolean(HTML_addKeyValueTableHeaders, ctx.addKeyValueTableHeaders);
+ addBeanTypeProperties = op.getBoolean(MSGPACK_addBeanTypeProperties, ctx.addBeanTypeProperties);
}
labelPattern = Pattern.compile("[\\?\\&]" + Pattern.quote(labelParameter) + "=([^\\&]*)");
this.absolutePathUriBase = getAbsolutePathUriBase();
@@ -165,4 +172,13 @@ public class HtmlSerializerSession extends XmlSerializerSession {
return addKeyValueTableHeaders;
}
+ /**
+ * Returns the {@link HtmlSerializerContext#HTML_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link HtmlSerializerContext#HTML_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public final boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerContext.java
index 6cdceb3..9b0afc5 100644
--- a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerContext.java
@@ -65,10 +65,29 @@ public final class JsonSerializerContext extends SerializerContext {
*/
public static final String JSON_escapeSolidus = "JsonSerializer.escapeSolidus";
+ /**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"JsonSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String JSON_addBeanTypeProperties = "JsonSerializer.addBeanTypeProperties";
final boolean
simpleMode,
- escapeSolidus;
+ escapeSolidus,
+ addBeanTypeProperties;
/**
* Constructor.
@@ -81,6 +100,7 @@ public final class JsonSerializerContext extends SerializerContext {
super(cf);
simpleMode = cf.getProperty(JSON_simpleMode, boolean.class, false);
escapeSolidus = cf.getProperty(JSON_escapeSolidus, boolean.class, false);
+ addBeanTypeProperties = cf.getProperty(JSON_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
@@ -89,6 +109,7 @@ public final class JsonSerializerContext extends SerializerContext {
.append("JsonSerializerContext", new ObjectMap()
.append("simpleMode", simpleMode)
.append("escapeSolidus", escapeSolidus)
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
index 1d99bf7..ebe569a 100644
--- a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializerSession.java
@@ -27,7 +27,10 @@ import org.apache.juneau.serializer.*;
*/
public final class JsonSerializerSession extends SerializerSession {
- private final boolean simpleMode, escapeSolidus;
+ private final boolean
+ simpleMode,
+ escapeSolidus,
+ addBeanTypeProperties;
/**
* Create a new session using properties specified in the context.
@@ -49,9 +52,11 @@ public final class JsonSerializerSession extends SerializerSession {
if (op == null || op.isEmpty()) {
simpleMode = ctx.simpleMode;
escapeSolidus = ctx.escapeSolidus;
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
} else {
simpleMode = op.getBoolean(JSON_simpleMode, ctx.simpleMode);
escapeSolidus = op.getBoolean(JSON_escapeSolidus, ctx.escapeSolidus);
+ addBeanTypeProperties = op.getBoolean(JSON_addBeanTypeProperties, ctx.addBeanTypeProperties);
}
}
@@ -73,6 +78,16 @@ public final class JsonSerializerSession extends SerializerSession {
return escapeSolidus;
}
+ /**
+ * Returns the {@link JsonSerializerContext#JSON_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link JsonSerializerContext#JSON_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public final boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
+ }
+
@Override /* ParserSession */
public JsonWriter getWriter() throws Exception {
Object output = getOutput();
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerContext.java
index 7fa6019..e74a041 100644
--- a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerContext.java
@@ -34,6 +34,28 @@ import org.apache.juneau.serializer.*;
public final class MsgPackSerializerContext extends SerializerContext {
/**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"MsgPackSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String MSGPACK_addBeanTypeProperties = "MsgPackSerializer.addBeanTypeProperties";
+
+ final boolean
+ addBeanTypeProperties;
+
+ /**
* Constructor.
* <p>
* Typically only called from {@link ContextFactory#getContext(Class)}.
@@ -42,12 +64,14 @@ public final class MsgPackSerializerContext extends SerializerContext {
*/
public MsgPackSerializerContext(ContextFactory cf) {
super(cf);
+ addBeanTypeProperties = cf.getProperty(MSGPACK_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
public ObjectMap asMap() {
return super.asMap()
.append("MsgPackSerializerContext", new ObjectMap()
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
index aa3eb0f..4b87867 100644
--- a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
@@ -12,6 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau.msgpack;
+import static org.apache.juneau.msgpack.MsgPackSerializerContext.*;
+
import java.lang.reflect.*;
import java.util.*;
@@ -27,6 +29,9 @@ import org.apache.juneau.serializer.*;
*/
public final class MsgPackSerializerSession extends SerializerSession {
+ private final boolean
+ addBeanTypeProperties;
+
/**
* Create a new session using properties specified in the context.
*
@@ -44,9 +49,24 @@ public final class MsgPackSerializerSession extends SerializerSession {
*/
protected MsgPackSerializerSession(MsgPackSerializerContext ctx, ObjectMap op, Object output, Method javaMethod, Locale locale, TimeZone timeZone, MediaType mediaType) {
super(ctx, op, output, javaMethod, locale, timeZone, mediaType);
+ if (op == null || op.isEmpty()) {
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
+ } else {
+ addBeanTypeProperties = op.getBoolean(MSGPACK_addBeanTypeProperties, ctx.addBeanTypeProperties);
+ }
+ }
+
+ /**
+ * Returns the {@link MsgPackSerializerContext#MSGPACK_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link MsgPackSerializerContext#MSGPACK_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public final boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
}
- @Override
+ @Override /*SerializerSession */
public MsgPackOutputStream getOutputStream() throws Exception {
Object output = getOutput();
if (output instanceof MsgPackOutputStream)
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
index 7d499e6..69b6b26 100644
--- a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
@@ -285,7 +285,7 @@ public class SerializerSession extends BeanSession {
*
* @return The {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting value for this session.
*/
- public final boolean isAddBeanTypeProperties() {
+ public boolean isAddBeanTypeProperties() {
return addBeanTypeProperties;
}
@@ -702,7 +702,7 @@ public class SerializerSession extends BeanSession {
if (eType == aType)
return null;
- if (! addBeanTypeProperties)
+ if (! isAddBeanTypeProperties())
return null;
String eTypeTn = eType.getDictionaryName();
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerContext.java
index 65867a5..ec9dca9 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerContext.java
@@ -51,9 +51,29 @@ public class UonSerializerContext extends SerializerContext {
*/
public static final String UON_encodeChars = "UonSerializer.encodeChars";
+ /**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"UonSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String UON_addBeanTypeProperties = "UonSerializer.addBeanTypeProperties";
+
final boolean
- encodeChars;
+ encodeChars,
+ addBeanTypeProperties;
/**
* Constructor.
@@ -65,6 +85,7 @@ public class UonSerializerContext extends SerializerContext {
public UonSerializerContext(ContextFactory cf) {
super(cf);
encodeChars = cf.getProperty(UON_encodeChars, boolean.class, false);
+ addBeanTypeProperties = cf.getProperty(UON_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
@@ -72,6 +93,7 @@ public class UonSerializerContext extends SerializerContext {
return super.asMap()
.append("UonSerializerContext", new ObjectMap()
.append("encodeChars", encodeChars)
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerSession.java
index b10f68e..e0beaf3 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializerSession.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.urlencoding;
+import static org.apache.juneau.msgpack.MsgPackSerializerContext.*;
import static org.apache.juneau.urlencoding.UonSerializerContext.*;
import java.lang.reflect.*;
@@ -28,7 +29,9 @@ import org.apache.juneau.serializer.*;
*/
public class UonSerializerSession extends SerializerSession {
- private final boolean encodeChars;
+ private final boolean
+ encodeChars,
+ addBeanTypeProperties;
/**
* Create a new session using properties specified in the context.
@@ -49,19 +52,13 @@ public class UonSerializerSession extends SerializerSession {
super(ctx, op, output, javaMethod, locale, timeZone, mediaType);
if (op == null || op.isEmpty()) {
encodeChars = ctx.encodeChars;
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
} else {
encodeChars = op.getBoolean(UON_encodeChars, ctx.encodeChars);
+ addBeanTypeProperties = op.getBoolean(MSGPACK_addBeanTypeProperties, ctx.addBeanTypeProperties);
}
}
- @Override /* SerializerSession */
- public final UonWriter getWriter() throws Exception {
- Object output = getOutput();
- if (output instanceof UonWriter)
- return (UonWriter)output;
- return new UonWriter(this, super.getWriter(), isUseWhitespace(), isEncodeChars(), isTrimStrings(), getRelativeUriBase(), getAbsolutePathUriBase());
- }
-
/**
* Returns the {@link UonSerializerContext#UON_encodeChars} setting value for this session.
*
@@ -70,4 +67,22 @@ public class UonSerializerSession extends SerializerSession {
public final boolean isEncodeChars() {
return encodeChars;
}
+
+ /**
+ * Returns the {@link UonSerializerContext#UON_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link UonSerializerContext#UON_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public final boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
+ }
+
+ @Override /* SerializerSession */
+ public final UonWriter getWriter() throws Exception {
+ Object output = getOutput();
+ if (output instanceof UonWriter)
+ return (UonWriter)output;
+ return new UonWriter(this, super.getWriter(), isUseWhitespace(), isEncodeChars(), isTrimStrings(), getRelativeUriBase(), getAbsolutePathUriBase());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/urlencoding/doc-files/rfc_uon.txt
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/doc-files/rfc_uon.txt b/juneau-core/src/main/java/org/apache/juneau/urlencoding/doc-files/rfc_uon.txt
index a78153f..7880064 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/doc-files/rfc_uon.txt
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/doc-files/rfc_uon.txt
@@ -81,12 +81,12 @@ Abstract
Using the syntax defined in this document, the equivalent
UON notation would be as follows:
- x=(id=1,name=John+Smith,uri=http://sample/
+ x=(id=1,name='John+Smith',uri=http://sample/
addressBook/person/1,addressBookUri=http://sample/
- addressBook,birthDate=1946-08-12T00:00:00Z,otherIds=%00,
+ addressBook,birthDate=1946-08-12T00:00:00Z,otherIds=null,
addresses=@((uri=http://sample/addressBook/
address/1,personUri=http://sample/addressBook/
- person/1,id=1,street=100+Main+Street,city=
+ person/1,id=1,street='100+Main+Street',city=
Anywhereville,state=NY,zip=12345,isCurrent=true)))
1. Language constraints
@@ -167,7 +167,13 @@ Abstract
a1=123&a2=1.23e1
-2.5. Strings
+2.5. Null values
+
+ Nulls are represented by the keyword 'null':
+
+ a1=null
+
+2.6. Strings
Strings are encapsulated in single quote (') characters.
@@ -209,13 +215,7 @@ Abstract
a1='foo~'bar~~baz'
-2.7. Null values
-
- Nulls are represented by the keyword 'null':
-
- a1=null
-
-2.8. Top-level attribute names
+2.7. Top-level attribute names
Top-level attribute names (e.g. "a1" in "&a1=foobar") are treated
as strings but for one exception. The '=' character must be
@@ -231,7 +231,7 @@ Abstract
Note that the '=' character is encoded in the attribute name,
but it is not necessary to have it encoded in the attribute value.
-2.9. URL-encoded characters
+2.8. URL-encoded characters
UON notation allows for any character, even UON grammar
characters, to be URL-encoded.
@@ -239,7 +239,7 @@ Abstract
The following query strings are fully equivalent in structure:
a1=(b1='x1',b2='x2')
- %61%31=%24%6F%28%62%31%3D%78%31%2C%62%32%3D%78%32%29
+ %61%31=%79%6f%75%20%61%72%65%20%61%20%6e%65%72%64%21
3. BNF
@@ -251,7 +251,7 @@ Abstract
value = (var | string | null)
string = ("'" litchar* "'") | litchar*
- null = "%00"
+ null = "null"
var = ovar | avar | nvar | boolean | number
ovar = "(" [pairs] ")"
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerContext.java
index 181eaa4..cac3b8a 100644
--- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerContext.java
@@ -138,11 +138,31 @@ public class XmlSerializerContext extends SerializerContext {
*/
public static final String XML_namespaces = "XmlSerializer.namespaces.list";
+ /**
+ * <b>Configuration property:</b> Add <js>"_type"</js> properties when needed.
+ * <p>
+ * <ul>
+ * <li><b>Name:</b> <js>"XmlSerializer.addBeanTypeProperties"</js>
+ * <li><b>Data type:</b> <code>Boolean</code>
+ * <li><b>Default:</b> <jk>false</jk>
+ * <li><b>Session-overridable:</b> <jk>true</jk>
+ * </ul>
+ * <p>
+ * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred through reflection.
+ * This is used to recreate the correct objects during parsing if the object types cannot be inferred.
+ * For example, when serializing a {@code Map<String,Object>} field, where the bean class cannot be determined from the value type.
+ * <p>
+ * When present, this value overrides the {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting and is
+ * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
+ */
+ public static final String XML_addBeanTypeProperties = "XmlSerializer.addBeanTypeProperties";
+
final boolean
autoDetectNamespaces,
enableNamespaces,
- addNamespaceUrlsToRoot;
+ addNamespaceUrlsToRoot,
+ addBeanTypeProperties;
final String defaultNamespace;
@@ -166,6 +186,7 @@ public class XmlSerializerContext extends SerializerContext {
defaultNamespace = cf.getProperty(XML_defaultNamespace, String.class, "{juneau:'http://www.apache.org/2013/Juneau'}");
xsNamespace = cf.getProperty(XML_xsNamespace, Namespace.class, new Namespace("xs", "http://www.w3.org/2001/XMLSchema"));
namespaces = cf.getProperty(XML_namespaces, Namespace[].class, new Namespace[0]);
+ addBeanTypeProperties = cf.getProperty(XML_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true));
}
@Override /* Context */
@@ -178,6 +199,7 @@ public class XmlSerializerContext extends SerializerContext {
.append("defaultNamespace", defaultNamespace)
.append("xsNamespace", xsNamespace)
.append("namespaces", namespaces)
+ .append("addBeanTypeProperties", addBeanTypeProperties)
);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
index 5ab38d3..c806704 100644
--- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.xml;
+import static org.apache.juneau.msgpack.MsgPackSerializerContext.*;
import static org.apache.juneau.xml.NamespaceFactory.*;
import static org.apache.juneau.xml.XmlSerializerContext.*;
@@ -34,7 +35,8 @@ public class XmlSerializerSession extends SerializerSession {
private final boolean
autoDetectNamespaces,
enableNamespaces,
- addNamespaceUrlsToRoot;
+ addNamespaceUrlsToRoot,
+ addBeanTypeProperties;
private Namespace
defaultNamespace;
@@ -67,6 +69,7 @@ public class XmlSerializerSession extends SerializerSession {
addNamespaces(ctx.namespaces);
defaultNamespace = findDefaultNamespace(ctx.defaultNamespace);
xsNamespace = ctx.xsNamespace;
+ addBeanTypeProperties = ctx.addBeanTypeProperties;
} else {
enableNamespaces = op.getBoolean(XML_enableNamespaces, ctx.enableNamespaces);
autoDetectNamespaces = op.getBoolean(XML_autoDetectNamespaces, ctx.autoDetectNamespaces);
@@ -74,6 +77,7 @@ public class XmlSerializerSession extends SerializerSession {
namespaces = (op.containsKey(XML_namespaces) ? parseNamespaces(op.get(XML_namespaces)) : ctx.namespaces);
defaultNamespace = findDefaultNamespace(op.containsKey(XML_defaultNamespace) ? op.getString(XML_defaultNamespace) : ctx.defaultNamespace);
xsNamespace = (op.containsKey(XML_xsNamespace) ? parseNamespace(op.get(XML_xsNamespace)) : ctx.xsNamespace);
+ addBeanTypeProperties = op.getBoolean(MSGPACK_addBeanTypeProperties, ctx.addBeanTypeProperties);
}
}
@@ -148,6 +152,16 @@ public class XmlSerializerSession extends SerializerSession {
}
/**
+ * Returns the {@link XmlSerializerContext#XML_addBeanTypeProperties} setting value for this session.
+ *
+ * @return The {@link XmlSerializerContext#XML_addBeanTypeProperties} setting value for this session.
+ */
+ @Override /* SerializerSession */
+ public boolean isAddBeanTypeProperties() {
+ return addBeanTypeProperties;
+ }
+
+ /**
* Returns the {@link XmlSerializerContext#XML_defaultNamespace} setting value in this context.
*
* @return The {@link XmlSerializerContext#XML_defaultNamespace} setting value in this context.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/94992115/juneau-core/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html
index c2f8fb9..af45a96 100644
--- a/juneau-core/src/main/javadoc/overview.html
+++ b/juneau-core/src/main/javadoc/overview.html
@@ -5383,6 +5383,7 @@
<h5 class='toc'>What's new in each release</h5>
<ul class='toc'>
+ <li><p><a class='doclink' href='#6.1.1'>6.1.1 (TBD)</a></p>
<li><p><a class='doclink' href='#6.1.0'>6.1.0 (TBD)</a></p>
<li><p><a class='doclink' href='#6.0.1'>6.0.1 (Jan 3, 2017)</a></p>
<li><p><a class='doclink' href='#6.0.0'>6.0.0 (Oct 3, 2016)</a></p>
@@ -5450,6 +5451,31 @@
<!-- ======================================================================================================== -->
+ <a id="6.1.1"></a>
+ <h3 class='topic' onclick='toggle(this)'>6.1.1 (TBD)</h3>
+ <div class='topic'>
+ <p>
+ Juneau 6.1.1 is ...
+ </p>
+
+ <h6 class='topic'>org.apache.juneau</h6>
+ <ul class='spaced-list'>
+ <li>New <code>addBeanTypeProperties</code> setting added to serializers to override the
+ {@link org.apache.juneau.serializer.SerializerContext#SERIALIZER_addBeanTypeProperties} setting
+ for individual serializers in a serializer group:
+ <ul>
+ <li>{@link org.apache.juneau.html.HtmlSerializerContext#HTML_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.json.JsonSerializerContext#JSON_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.msgpack.MsgPackSerializerContext#MSGPACK_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.uon.UonSerializerContext#UON_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.xml.XmlSerializerContext#XML_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.rdf.RdfSerializerContext#RDF_addBeanTypeProperties}
+ </ul>
+ </ul>
+ </div>
+
+
+ <!-- ======================================================================================================== -->
<a id="6.1.0"></a>
<h3 class='topic' onclick='toggle(this)'>6.1.0 (TBD)</h3>
<div class='topic'>