Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AF916200BEB for ; Wed, 28 Dec 2016 22:03:43 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AE040160B2E; Wed, 28 Dec 2016 21:03:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 61F8E160B2A for ; Wed, 28 Dec 2016 22:03:41 +0100 (CET) Received: (qmail 15623 invoked by uid 500); 28 Dec 2016 21:03:40 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 15614 invoked by uid 99); 28 Dec 2016 21:03:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Dec 2016 21:03:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 118E0C0613 for ; Wed, 28 Dec 2016 21:03:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Kx9IIPLG__0a for ; Wed, 28 Dec 2016 21:03:33 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 7F7915FDFD for ; Wed, 28 Dec 2016 21:03:31 +0000 (UTC) Received: (qmail 15474 invoked by uid 99); 28 Dec 2016 21:03:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Dec 2016 21:03:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87C45F2DC7; Wed, 28 Dec 2016 21:03:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Wed, 28 Dec 2016 21:03:33 -0000 Message-Id: In-Reply-To: <11a74f2541644afcbd9d821b34d90785@git.apache.org> References: <11a74f2541644afcbd9d821b34d90785@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/9] incubator-juneau git commit: JUNEAU-26 - Add support for date localization. archived-at: Wed, 28 Dec 2016 21:03:43 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/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 88ccd8f..6a1725f 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 @@ -36,24 +36,27 @@ import org.apache.juneau.serializer.*; * *
Configurable properties on the URL-Encoding and UON serializers
* - * + * * * * * * + * * * * * * * + * * * * * * * + * * *
Setting nameDescriptionData typeDefault value
Setting nameDescriptionData typeDefault valueSession overridable
{@link #UON_simpleMode}Use simplified output.Booleanfalsetrue
{@link #UON_useWhitespace}Use whitespace.Booleanfalsetrue
{@link #UON_encodeChars}Encode non-valid URI characters.Booleanfalse for {@link UonSerializer}
true for {@link UrlEncodingSerializer}
true
* @@ -74,6 +77,7 @@ public class UonSerializerContext extends SerializerContext { *
  • Name: "UonSerializer.simpleMode" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, type flags will not be prepended to values in most cases. @@ -133,6 +137,7 @@ public class UonSerializerContext extends SerializerContext { *

  • Name: "UonSerializer.useWhitespace" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, whitespace is added to the output to improve readability. @@ -146,6 +151,7 @@ public class UonSerializerContext extends SerializerContext { *

  • Name: "UonSerializer.encodeChars" *
  • Data type: Boolean *
  • Default: false for {@link UonSerializer}, true for {@link UrlEncodingSerializer} + *
  • Session-overridable: true * *

    * Encode non-valid URI characters with "%xx" constructs. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/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 aa4d08a..39ace7a 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 @@ -15,6 +15,7 @@ package org.apache.juneau.urlencoding; import static org.apache.juneau.urlencoding.UonSerializerContext.*; import java.lang.reflect.*; +import java.util.*; import org.apache.juneau.*; import org.apache.juneau.json.*; @@ -34,14 +35,17 @@ public class UonSerializerSession extends SerializerSession { * * @param ctx The context creating this session object. * The context contains all the configuration settings for this object. - * @param beanContext The bean context being used. * @param output The output object. See {@link JsonSerializerSession#getWriter()} for valid class types. * @param op The override properties. * These override any context properties defined in the context. * @param javaMethod The java method that called this parser, usually the method in a REST servlet. + * @param locale The session locale. + * If null, then the locale defined on the context is used. + * @param timeZone The session timezone. + * If null, then the timezone defined on the context is used. */ - protected UonSerializerSession(UonSerializerContext ctx, BeanContext beanContext, Object output, ObjectMap op, Method javaMethod) { - super(ctx, beanContext, output, op, javaMethod); + protected UonSerializerSession(UonSerializerContext ctx, ObjectMap op, Object output, Method javaMethod, Locale locale, TimeZone timeZone) { + super(ctx, op, output, javaMethod, locale, timeZone); if (op == null || op.isEmpty()) { simpleMode = ctx.simpleMode; useWhitespace = ctx.useWhitespace; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java index 224d0c3..0047ab4 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java @@ -65,12 +65,11 @@ public class UrlEncodingParser extends UonParser { private T parseAnything(UrlEncodingParserSession session, ClassMeta eType, ParserReader r, Object outer) throws Exception { - BeanContext bc = session.getBeanContext(); if (eType == null) eType = (ClassMeta)object(); PojoSwap transform = (PojoSwap)eType.getPojoSwap(); ClassMeta sType = eType.getSerializedClassMeta(); - BeanDictionary bd = bc.getBeanDictionary(); + BeanDictionary bd = session.getBeanDictionary(); int c = r.peek(); if (c == '?') @@ -79,40 +78,40 @@ public class UrlEncodingParser extends UonParser { Object o; if (sType.isObject()) { - ObjectMap m = new ObjectMap(bc); - parseIntoMap(session, r, m, bc.string(), bc.object()); + ObjectMap m = new ObjectMap(session); + parseIntoMap(session, r, m, session.string(), session.object()); if (m.containsKey("_value")) o = m.get("_value"); else o = bd.cast(m); } else if (sType.isMap()) { - Map m = (sType.canCreateNewInstance() ? (Map)sType.newInstance() : new ObjectMap(bc)); + Map m = (sType.canCreateNewInstance() ? (Map)sType.newInstance() : new ObjectMap(session)); o = parseIntoMap(session, r, m, sType.getKeyType(), sType.getValueType()); } else if (sType.canCreateNewInstanceFromObjectMap(outer)) { - ObjectMap m = new ObjectMap(bc); + ObjectMap m = new ObjectMap(session); parseIntoMap(session, r, m, string(), object()); o = sType.newInstanceFromObjectMap(outer, m); } else if (sType.canCreateNewBean(outer)) { - BeanMap m = bc.newBeanMap(outer, sType.getInnerClass()); + BeanMap m = session.newBeanMap(outer, sType.getInnerClass()); m = parseIntoBeanMap(session, r, m); o = m == null ? null : m.getBean(); } else { // It could be a non-bean with _type attribute. - ObjectMap m = new ObjectMap(bc); + ObjectMap m = new ObjectMap(session); ClassMeta valueType = object(); parseIntoMap(session, r, m, string(), valueType); - if (m.containsKey(bc.getBeanTypePropertyName())) + if (m.containsKey(session.getBeanTypePropertyName())) o = bd.cast(m); else if (m.containsKey("_value")) - o = session.getBeanContext().convertToType(m.get("_value"), sType); + o = session.convertToType(m.get("_value"), sType); else if (sType.isCollection()) { // ?1=foo&2=bar... - Collection c2 = sType.canCreateNewInstance() ? (Collection)sType.newInstance() : new ObjectList(bc); + Collection c2 = sType.canCreateNewInstance() ? (Collection)sType.newInstance() : new ObjectList(session); Map t = new TreeMap(); for (Map.Entry e : m.entrySet()) { String k = e.getKey(); if (StringUtils.isNumeric(k)) - t.put(Integer.valueOf(k), bc.convertToType(e.getValue(), sType.getElementType())); + t.put(Integer.valueOf(k), session.convertToType(e.getValue(), sType.getElementType())); } c2.addAll(t.values()); o = c2; @@ -124,7 +123,7 @@ public class UrlEncodingParser extends UonParser { } if (transform != null && o != null) - o = transform.unswap(o, eType, bc); + o = transform.unswap(session, o, eType); if (outer != null) setParent(eType, o, outer); @@ -157,7 +156,7 @@ public class UrlEncodingParser extends UonParser { return m; r.unread(); Object attr = parseAttr(session, r, true); - currAttr = session.trim(session.getBeanContext().convertToType(attr, keyType)); + currAttr = session.trim(session.convertToType(attr, keyType)); state = S2; c = 0; // Avoid isInEscape if c was '\' } else if (state == S2) { @@ -184,7 +183,7 @@ public class UrlEncodingParser extends UonParser { if (m.containsKey(currAttr) && valueType.isObject()) { Object v2 = m.get(currAttr); if (! (v2 instanceof ObjectList)) { - v2 = new ObjectList(v2); + v2 = new ObjectList(v2).setBeanSession(session); m.put(currAttr, (V)v2); } ((ObjectList)v2).add(value); @@ -218,8 +217,6 @@ public class UrlEncodingParser extends UonParser { private BeanMap parseIntoBeanMap(UrlEncodingParserSession session, ParserReader r, BeanMap m) throws Exception { - BeanContext bc = session.getBeanContext(); - int c = r.peek(); if (c == -1) return m; @@ -258,7 +255,7 @@ public class UrlEncodingParser extends UonParser { } } else if (state == S3) { if (c == -1 || c == '\u0001') { - if (! currAttr.equals(bc.getBeanTypePropertyName())) { + if (! currAttr.equals(session.getBeanTypePropertyName())) { BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); if (pMeta == null) { if (m.getMeta().isSubTyped()) { @@ -280,7 +277,7 @@ public class UrlEncodingParser extends UonParser { return m; state = S1; } else { - if (! currAttr.equals(bc.getBeanTypePropertyName())) { + if (! currAttr.equals(session.getBeanTypePropertyName())) { BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); if (pMeta == null) { if (m.getMeta().isSubTyped()) { @@ -418,8 +415,7 @@ public class UrlEncodingParser extends UonParser { private Object[] parseArgs(UrlEncodingParserSession session, ParserReader r, ClassMeta[] argTypes) throws Exception { // TODO - This can be made more efficient. - BeanContext bc = session.getBeanContext(); - ClassMeta> cm = bc.getMapClassMeta(TreeMap.class, Integer.class, String.class); + ClassMeta> cm = session.getMapClassMeta(TreeMap.class, Integer.class, String.class); TreeMap m = parseAnything(session, cm, r, session.getOuter()); Object[] vals = m.values().toArray(new Object[m.size()]); if (vals.length != argTypes.length) @@ -443,7 +439,7 @@ public class UrlEncodingParser extends UonParser { public T parseParameter(CharSequence in, ClassMeta type) throws ParseException { if (in == null) return null; - UonParserSession session = createParameterContext(in); + UonParserSession session = createParameterSession(in); try { UonReader r = session.getReader(); return super.parseAnything(session, type, r, null, true, null); @@ -465,7 +461,19 @@ public class UrlEncodingParser extends UonParser { * @throws ParseException */ public T parseParameter(CharSequence in, Class type) throws ParseException { - return parseParameter(in, getBeanContext().getClassMeta(type)); + if (in == null) + return null; + UonParserSession session = createParameterSession(in); + try { + UonReader r = session.getReader(); + return super.parseAnything(session, session.getClassMeta(type), r, null, true, null); + } catch (ParseException e) { + throw e; + } catch (Exception e) { + throw new ParseException(session, e); + } finally { + session.close(); + } } //-------------------------------------------------------------------------------- @@ -473,14 +481,14 @@ public class UrlEncodingParser extends UonParser { //-------------------------------------------------------------------------------- @Override /* Parser */ - public UrlEncodingParserSession createSession(Object input, ObjectMap properties, Method javaMethod, Object outer) { - return new UrlEncodingParserSession(getContext(UrlEncodingParserContext.class), getBeanContext(), input, properties, javaMethod, outer); + public UrlEncodingParserSession createSession(Object input, ObjectMap op, Method javaMethod, Object outer, Locale locale, TimeZone timeZone) { + return new UrlEncodingParserSession(getContext(UrlEncodingParserContext.class), op, input, javaMethod, outer, locale, timeZone); } @Override /* Parser */ protected T doParse(ParserSession session, ClassMeta type) throws Exception { UrlEncodingParserSession s = (UrlEncodingParserSession)session; - type = s.getBeanContext().normalizeClassMeta(type); + type = session.normalizeClassMeta(type); UonReader r = s.getReader(); T o = parseAnything(s, type, r, s.getOuter()); return o; @@ -500,7 +508,7 @@ public class UrlEncodingParser extends UonParser { UonReader r = s.getReader(); if (r.peek() == '?') r.read(); - m = parseIntoMap(s, r, m, s.getBeanContext().getClassMeta(keyType), s.getBeanContext().getClassMeta(valueType)); + m = parseIntoMap(s, r, m, session.getClassMeta(keyType), session.getClassMeta(valueType)); return m; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserContext.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserContext.java index 9ca1304..81df420 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserContext.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserContext.java @@ -32,11 +32,30 @@ import org.apache.juneau.*; * *

    * See {@link ContextFactory} for more information about context properties. + * + *

    Configurable properties on the URL-Encoding parser
    + * + * + * + * + * + * + * + * + * + *
    Setting nameDescriptionData typeDefault valueSession overridable
    {@link #URLENC_expandedParams}Serialize bean property collections/arrays as separate key/value pairs.Booleanfalsetrue
    */ public class UrlEncodingParserContext extends UonParserContext { /** - * Serialize bean property collections/arrays as separate key/value pairs ({@link Boolean}, default=false). + * Configuration property: Serialize bean property collections/arrays as separate key/value pairs. + *

    + *

      + *
    • Name: "UrlEncoding.expandedParams" + *
    • Data type: Boolean + *
    • Default: false + *
    • Session-overridable: true + *
    *

    * If false, serializing the array [1,2,3] results in ?key=$a(1,2,3). * If true, serializing the same array results in ?key=1&key=2&key=3. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java index 00cc1e6..f611d9a 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java @@ -16,6 +16,7 @@ import static org.apache.juneau.urlencoding.UrlEncodingParserContext.*; import java.io.*; import java.lang.reflect.*; +import java.util.*; import org.apache.juneau.*; @@ -33,7 +34,6 @@ public class UrlEncodingParserSession extends UonParserSession { * * @param ctx The context creating this session object. * The context contains all the configuration settings for this object. - * @param beanContext The bean context being used. * @param input The input. Can be any of the following types: *

      *
    • null @@ -46,9 +46,13 @@ public class UrlEncodingParserSession extends UonParserSession { * These override any context properties defined in the context. * @param javaMethod The java method that called this parser, usually the method in a REST servlet. * @param outer The outer object for instantiating top-level non-static inner classes. + * @param locale The session locale. + * If null, then the locale defined on the context is used. + * @param timeZone The session timezone. + * If null, then the timezone defined on the context is used. */ - public UrlEncodingParserSession(UrlEncodingParserContext ctx, BeanContext beanContext, Object input, ObjectMap op, Method javaMethod, Object outer) { - super(ctx, beanContext, input, op, javaMethod, outer); + public UrlEncodingParserSession(UrlEncodingParserContext ctx, ObjectMap op, Object input, Method javaMethod, Object outer, Locale locale, TimeZone timeZone) { + super(ctx, op, input, javaMethod, outer, locale, timeZone); if (op == null || op.isEmpty()) { expandedParams = ctx.expandedParams; } else { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java index 7abf2ac..5b8116c 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java @@ -220,7 +220,6 @@ public class UrlEncodingSerializer extends UonSerializer { */ @SuppressWarnings({ "rawtypes", "unchecked" }) private SerializerWriter serializeAnything(UrlEncodingSerializerSession session, UonWriter out, Object o) throws Exception { - BeanContext bc = session.getBeanContext(); boolean addTypeProperty; // Add "_type" attribute to element? ClassMeta aType; // The actual type @@ -237,12 +236,12 @@ public class UrlEncodingSerializer extends UonSerializer { // Swap if necessary PojoSwap swap = aType.getPojoSwap(); if (swap != null) { - o = swap.swap(o, bc); + o = swap.swap(session, o); // If the getSwapClass() method returns Object, we need to figure out // the actual type now. if (sType.isObject()) - sType = bc.getClassMetaForObject(o); + sType = session.getClassMetaForObject(o); } if (sType.isMap()) { @@ -253,9 +252,9 @@ public class UrlEncodingSerializer extends UonSerializer { } else if (sType.hasToObjectMapMethod()) { serializeMap(session, out, sType.toObjectMap(o), sType); } else if (sType.isBean()) { - serializeBeanMap(session, out, bc.forBean(o), addTypeProperty); + serializeBeanMap(session, out, session.toBeanMap(o), addTypeProperty); } else if (sType.isCollection()) { - serializeMap(session, out, getCollectionMap((Collection)o), bc.getMapClassMeta(Map.class, Integer.class, sType.getElementType())); + serializeMap(session, out, getCollectionMap((Collection)o), session.getMapClassMeta(Map.class, Integer.class, sType.getElementType())); } else { // All other types can't be serialized as key/value pairs, so we create a // mock key/value pair with a "_value" key. @@ -367,7 +366,7 @@ public class UrlEncodingSerializer extends UonSerializer { //-------------------------------------------------------------------------------- /** - * Converts the specified object to a string using this serializers {@link BeanContext#convertToType(Object, Class)} method + * Converts the specified object to a string using this serializers {@link BeanSession#convertToType(Object, Class)} method * and runs {@link URLEncoder#encode(String,String)} against the results. * Useful for constructing URL parts. * @@ -383,7 +382,7 @@ public class UrlEncodingSerializer extends UonSerializer { return o.toString(); StringWriter w = new StringWriter(); - UonSerializerSession s = createSession(w, null, null); + UonSerializerSession s = createSession(w, null, null, null, null); super.doSerialize(s, o); return w.toString(); } catch (Exception e) { @@ -397,8 +396,8 @@ public class UrlEncodingSerializer extends UonSerializer { //-------------------------------------------------------------------------------- @Override /* Serializer */ - public UrlEncodingSerializerSession createSession(Object output, ObjectMap properties, Method javaMethod) { - return new UrlEncodingSerializerSession(getContext(UrlEncodingSerializerContext.class), getBeanContext(), output, properties, javaMethod); + public UrlEncodingSerializerSession createSession(Object output, ObjectMap op, Method javaMethod, Locale locale, TimeZone timeZone) { + return new UrlEncodingSerializerSession(getContext(UrlEncodingSerializerContext.class), op, output, javaMethod, locale, timeZone); } @Override /* Serializer */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerContext.java index 932447e..5c2c6ff 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerContext.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerContext.java @@ -32,11 +32,31 @@ import org.apache.juneau.*; *
    *

    * See {@link ContextFactory} for more information about context properties. + * + * + *

    Configurable properties on the URL-Encoding serializer
    + * + * + * + * + * + * + * + * + * + *
    Setting nameDescriptionData typeDefault valueSession overridable
    {@link #URLENC_expandedParams}Serialize bean property collections/arrays as separate key/value pairs.Booleanfalsetrue
    */ public class UrlEncodingSerializerContext extends UonSerializerContext { /** - * Serialize bean property collections/arrays as separate key/value pairs ({@link Boolean}, default=false). + * Configuration property: Serialize bean property collections/arrays as separate key/value pairs. + *

    + *

      + *
    • Name: "UrlEncoding.expandedParams" + *
    • Data type: Boolean + *
    • Default: false + *
    • Session-overridable: true + *
    *

    * If false, serializing the array [1,2,3] results in ?key=$a(1,2,3). * If true, serializing the same array results in ?key=1&key=2&key=3. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java index 192122a..c762e90 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java @@ -15,6 +15,7 @@ package org.apache.juneau.urlencoding; import static org.apache.juneau.urlencoding.UrlEncodingParserContext.*; import java.lang.reflect.*; +import java.util.*; import org.apache.juneau.*; import org.apache.juneau.json.*; @@ -33,14 +34,17 @@ public class UrlEncodingSerializerSession extends UonSerializerSession { * * @param ctx The context creating this session object. * The context contains all the configuration settings for this object. - * @param beanContext The bean context being used. * @param output The output object. See {@link JsonSerializerSession#getWriter()} for valid class types. * @param op The override properties. * These override any context properties defined in the context. * @param javaMethod The java method that called this parser, usually the method in a REST servlet. + * @param locale The session locale. + * If null, then the locale defined on the context is used. + * @param timeZone The session timezone. + * If null, then the timezone defined on the context is used. */ - public UrlEncodingSerializerSession(UrlEncodingSerializerContext ctx, BeanContext beanContext, Object output, ObjectMap op, Method javaMethod) { - super(ctx, beanContext, output, op, javaMethod); + public UrlEncodingSerializerSession(UrlEncodingSerializerContext ctx, ObjectMap op, Object output, Method javaMethod, Locale locale, TimeZone timeZone) { + super(ctx, op, output, javaMethod, locale, timeZone); if (op == null || op.isEmpty()) { expandedParams = ctx.expandedParams; } else { @@ -74,7 +78,7 @@ public class UrlEncodingSerializerSession extends UonSerializerSession { public final boolean shouldUseExpandedParams(Object value) { if (value == null || ! expandedParams) return false; - ClassMeta cm = getBeanContext().getClassMetaForObject(value).getSerializedClassMeta(); + ClassMeta cm = getClassMetaForObject(value).getSerializedClassMeta(); if (cm.isArray() || cm.isCollection()) { if (expandedParams) return true; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/utils/PojoIntrospector.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/PojoIntrospector.java b/juneau-core/src/main/java/org/apache/juneau/utils/PojoIntrospector.java index de21fb2..44d5580 100644 --- a/juneau-core/src/main/java/org/apache/juneau/utils/PojoIntrospector.java +++ b/juneau-core/src/main/java/org/apache/juneau/utils/PojoIntrospector.java @@ -79,7 +79,7 @@ public final class PojoIntrospector { public Object invokeMethod(Method method, Reader args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, ParseException, IOException { if (o == null) return null; - ClassMeta[] argTypes = p.getBeanContext().getClassMetas(method.getParameterTypes()); + ClassMeta[] argTypes = p.getBeanContext().createSession().getClassMetas(method.getParameterTypes()); Object[] params = args == null ? null : p.parseArgs(args, argTypes); return method.invoke(o, params); } @@ -108,7 +108,7 @@ public final class PojoIntrospector { public Object invokeMethod(String method, String args) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException, ParseException, IOException { if (o == null) return null; - Method m = p.getBeanContext().getClassMeta(o.getClass()).getPublicMethods().get(method); + Method m = p.getBeanContext().createSession().getClassMeta(o.getClass()).getPublicMethods().get(method); if (m == null) throw new NoSuchMethodException(method); return invokeMethod(m, args == null ? null : new StringReader(args)); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java b/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java index 554204c..1d062f4 100644 --- a/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java +++ b/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java @@ -199,18 +199,18 @@ public final class PojoQuery { private Object input; private ClassMeta type; - private BeanContext beanContext; + private BeanSession session; /** * Constructor. * * @param input The POJO we're going to be filtering. - * @param beanContext The bean context to use to create bean maps for beans. + * @param session The bean session to use to create bean maps for beans. */ - public PojoQuery(Object input, BeanContext beanContext) { + public PojoQuery(Object input, BeanSession session) { this.input = input; - this.type = beanContext.getClassMetaForObject(input); - this.beanContext = beanContext; + this.type = session.getClassMetaForObject(input); + this.session = session; } /** @@ -293,16 +293,16 @@ public final class PojoQuery { private Object replaceWithMutables(Object o) { if (o == null) return null; - ClassMeta cm = beanContext.getClassMetaForObject(o); + ClassMeta cm = session.getClassMetaForObject(o); if (cm.isCollection()) { - ObjectList l = new DelegateList(beanContext.getClassMetaForObject(o)); + ObjectList l = new DelegateList(session.getClassMetaForObject(o)); for (Object o2 : (Collection)o) l.add(replaceWithMutables(o2)); return l; } if (cm.isMap() && o instanceof BeanMap) { BeanMap bm = (BeanMap)o; - DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(), beanContext); + DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(), session); for (BeanMapEntry e : (Set)bm.entrySet()) { ClassMeta ct1 = e.getMeta().getClassMeta(); if (ct1.isArray() || ct1.isBean() || ct1.isCollection() || ct1.isMap() || ct1.isObject()) @@ -313,8 +313,8 @@ public final class PojoQuery { return dbm; } if (cm.isBean()) { - BeanMap bm = beanContext.forBean(o); - DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(), beanContext); + BeanMap bm = session.toBeanMap(o); + DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(), session); for (BeanMapEntry e : (Set)bm.entrySet()) { ClassMeta ct1 = e.getMeta().getClassMeta(); if (ct1.isArray() || ct1.isBean() || ct1.isCollection() || ct1.isMap() || ct1.isObject()) { @@ -333,7 +333,7 @@ public final class PojoQuery { } if (cm.isMap()) { Map m = (Map)o; - DelegateMap dm = new DelegateMap(beanContext.getClassMetaForObject(m)); + DelegateMap dm = new DelegateMap(session.getClassMetaForObject(m)); for (Map.Entry e : (Set)m.entrySet()) dm.put(e.getKey().toString(), replaceWithMutables(e.getValue())); return dm; @@ -484,7 +484,7 @@ public final class PojoQuery { Object value = e.getValue(); IMatcher matcher = null; if (value instanceof String) - matcher = getObjectMatcherForType((String)value, ignoreCase, beanContext.object()); + matcher = getObjectMatcherForType((String)value, ignoreCase, session.object()); else if (value instanceof ObjectMap) matcher = new MapMatcher((ObjectMap)value, ignoreCase); else http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/utils/PojoRest.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/PojoRest.java b/juneau-core/src/main/java/org/apache/juneau/utils/PojoRest.java index 5efdbca..6f690cf 100644 --- a/juneau-core/src/main/java/org/apache/juneau/utils/PojoRest.java +++ b/juneau-core/src/main/java/org/apache/juneau/utils/PojoRest.java @@ -119,7 +119,7 @@ public final class PojoRest { private static final int GET=1, PUT=2, POST=3, DELETE=4; private ReaderParser parser = JsonParser.DEFAULT; - private final BeanContext bc; + private final BeanSession session; /** If true, the root cannot be overwritten */ private boolean rootLocked = false; @@ -150,8 +150,8 @@ public final class PojoRest { if (parser == null) parser = JsonParser.DEFAULT; this.parser = parser; - this.bc = parser.getBeanContext(); - this.root = new JsonNode(null, null, o, bc.object()); + this.session = parser.getBeanContext().createSession(); + this.root = new JsonNode(null, null, o, session.object()); } /** @@ -200,7 +200,7 @@ public final class PojoRest { /** * Retrieves the element addressed by the URL as the specified object type. *

    - * Will convert object to the specified type per {@link BeanContext#convertToType(Object, ClassMeta)}. + * Will convert object to the specified type per {@link BeanSession#convertToType(Object, ClassMeta)}. * * @param type The specified object type. * @param url The URL of the element to retrieve. @@ -216,7 +216,7 @@ public final class PojoRest { /** * Retrieves the element addressed by the URL as the specified object type. *

    - * Will convert object to the specified type per {@link BeanContext#convertToType(Object, ClassMeta)}. + * Will convert object to the specified type per {@link BeanSession#convertToType(Object, ClassMeta)}. * * @param type The specified object type. * @param url The URL of the element to retrieve. @@ -230,7 +230,7 @@ public final class PojoRest { Object o = service(GET, url, null); if (o == null) return def; - return bc.convertToType(o, type); + return session.convertToType(o, type); } /** @@ -495,7 +495,7 @@ public final class PojoRest { Object o = get(url); if (o == null) return null; - return bc.getClassMeta(o.getClass()).getPublicMethods().keySet(); + return session.getClassMeta(o.getClass()).getPublicMethods().keySet(); } /** @@ -605,7 +605,7 @@ public final class PojoRest { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; - root = new JsonNode(null, null, val, bc.object()); + root = new JsonNode(null, null, val, session.object()); return o; } JsonNode n = (parentUrl == null ? root : getNode(parentUrl, root)); @@ -626,14 +626,14 @@ public final class PojoRest { return url; } if (pct.isBean()) { - BeanMap m = bc.forBean(po); + BeanMap m = session.toBeanMap(po); m.put(n.keyName, o); return url; } throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' with parent node type ''{1}''", url, pct); } if (cm.isBean()) - return bc.forBean(o).put(childKey, val); + return session.toBeanMap(o).put(childKey, val); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' whose parent is of type ''{1}''", url, cm); } @@ -668,7 +668,7 @@ public final class PojoRest { return url + "/" + (o2.length-1); } if (pct.isBean()) { - BeanMap m = bc.forBean(po); + BeanMap m = session.toBeanMap(po); m.put(childKey, o2); return url + "/" + (o2.length-1); } @@ -687,7 +687,7 @@ public final class PojoRest { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; - root = new JsonNode(null, null, null, bc.object()); + root = new JsonNode(null, null, null, session.object()); return o; } JsonNode n = (parentUrl == null ? root : getNode(parentUrl, root)); @@ -708,14 +708,14 @@ public final class PojoRest { return old; } if (pct.isBean()) { - BeanMap m = bc.forBean(po); + BeanMap m = session.toBeanMap(po); m.put(n.keyName, o2); return old; } throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' with parent node type ''{1}''", url, pct); } if (cm.isBean()) - return bc.forBean(o).put(childKey, null); + return session.toBeanMap(o).put(childKey, null); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' whose parent is of type ''{1}''", url, cm); } @@ -764,9 +764,9 @@ public final class PojoRest { this.parent = parent; if (cm == null || cm.isObject()) { if (o == null) - cm = bc.object(); + cm = session.object(); else - cm = bc.getClassMetaForObject(o); + cm = session.getClassMetaForObject(o); } this.cm = cm; } @@ -808,7 +808,7 @@ public final class PojoRest { o2 = a[key]; ct2 = cm.getElementType(); } else if (cm.isBean()) { - BeanMap m = bc.forBean(o); + BeanMap m = session.toBeanMap(o); o2 = m.get(parentKey); BeanPropertyMeta pMeta = m.getPropertyMeta(parentKey); if (pMeta == null) @@ -829,7 +829,7 @@ public final class PojoRest { if (cm == null) return in; if (cm.isBean() && in instanceof Map) - return bc.convertToType(in, cm); + return session.convertToType(in, cm); return in; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java index 9a7bf88..a1f5b7f 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java +++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java @@ -58,16 +58,15 @@ public class XmlParser extends ReaderParser { private T parseAnything(XmlParserSession session, ClassMeta eType, String currAttr, XMLStreamReader r, Object outer, boolean isRoot, BeanPropertyMeta pMeta) throws Exception { - BeanContext bc = session.getBeanContext(); if (eType == null) eType = (ClassMeta)object(); PojoSwap transform = (PojoSwap)eType.getPojoSwap(); ClassMeta sType = eType.getSerializedClassMeta(); session.setCurrentClass(sType); - BeanDictionary bd = (pMeta == null ? bc.getBeanDictionary() : pMeta.getBeanDictionary()); + BeanDictionary bd = (pMeta == null ? session.getBeanDictionary() : pMeta.getBeanDictionary()); String wrapperAttr = (isRoot && session.isPreserveRootElement()) ? r.getName().getLocalPart() : null; - String typeAttr = r.getAttributeValue(null, bc.getBeanTypePropertyName()); + String typeAttr = r.getAttributeValue(null, session.getBeanTypePropertyName()); int jsonType = getJsonType(typeAttr); String b = r.getAttributeValue(session.getXsiNs(), "nil"); if (b == null) @@ -105,13 +104,13 @@ public class XmlParser extends ReaderParser { if (sType.isObject()) { if (jsonType == OBJECT) { - ObjectMap m = new ObjectMap(bc); + ObjectMap m = new ObjectMap(session); parseIntoMap(session, r, m, string(), object(), pMeta); if (wrapperAttr != null) - m = new ObjectMap(bc).append(wrapperAttr, m); + m = new ObjectMap(session).append(wrapperAttr, m); o = bd.cast(m); } else if (jsonType == ARRAY) - o = parseIntoCollection(session, r, new ObjectList(bc), object(), pMeta); + o = parseIntoCollection(session, r, new ObjectList(session), object(), pMeta); else if (jsonType == STRING) { o = session.decodeString(r.getElementText()); if (sType.isChar()) @@ -130,23 +129,23 @@ public class XmlParser extends ReaderParser { } else if (sType.isChar()) { o = session.decodeString(r.getElementText()).charAt(0); } else if (sType.isMap()) { - Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(bc)); + Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(session)); o = parseIntoMap(session, r, m, sType.getKeyType(), sType.getValueType(), pMeta); if (wrapperAttr != null) - o = new ObjectMap(bc).append(wrapperAttr, m); + o = new ObjectMap(session).append(wrapperAttr, m); } else if (sType.isCollection()) { - Collection l = (sType.canCreateNewInstance(outer) ? (Collection)sType.newInstance(outer) : new ObjectList(bc)); + Collection l = (sType.canCreateNewInstance(outer) ? (Collection)sType.newInstance(outer) : new ObjectList(session)); o = parseIntoCollection(session, r, l, sType.getElementType(), pMeta); } else if (sType.isNumber()) { o = parseNumber(session.decodeLiteral(r.getElementText()), (Class)sType.getInnerClass()); } else if (sType.canCreateNewInstanceFromObjectMap(outer)) { - ObjectMap m = new ObjectMap(bc); + ObjectMap m = new ObjectMap(session); parseIntoMap(session, r, m, string(), object(), pMeta); o = sType.newInstanceFromObjectMap(outer, m); } else if (sType.canCreateNewBean(outer)) { if (sType.getExtendedMeta(XmlClassMeta.class).getFormat() == XmlFormat.COLLAPSED) { String fieldName = r.getLocalName(); - BeanMap m = bc.newBeanMap(outer, sType.getInnerClass()); + BeanMap m = session.newBeanMap(outer, sType.getInnerClass()); BeanPropertyMeta bpm = m.getMeta().getExtendedMeta(XmlBeanMeta.class).getPropertyMeta(fieldName); ClassMeta cm = m.getMeta().getClassMeta(); Object value = parseAnything(session, cm, currAttr, r, m.getBean(false), false, null); @@ -154,22 +153,22 @@ public class XmlParser extends ReaderParser { bpm.set(m, value); o = m.getBean(); } else { - BeanMap m = bc.newBeanMap(outer, sType.getInnerClass()); + BeanMap m = session.newBeanMap(outer, sType.getInnerClass()); o = parseIntoBean(session, r, m).getBean(); } } else if (sType.isArray()) { ArrayList l = (ArrayList)parseIntoCollection(session, r, new ArrayList(), sType.getElementType(), pMeta); - o = bc.toArray(sType, l); + o = session.toArray(sType, l); } else if (sType.canCreateNewInstanceFromString(outer)) { o = sType.newInstanceFromString(outer, session.decodeString(r.getElementText())); } else if (sType.canCreateNewInstanceFromNumber(outer)) { - o = sType.newInstanceFromNumber(outer, parseNumber(session.decodeLiteral(r.getElementText()), sType.getNewInstanceFromNumberClass())); + o = sType.newInstanceFromNumber(session, outer, parseNumber(session.decodeLiteral(r.getElementText()), sType.getNewInstanceFromNumberClass())); } else { throw new ParseException(session, "Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); } if (transform != null && o != null) - o = transform.unswap(o, eType, bc); + o = transform.unswap(session, o, eType); if (outer != null) setParent(eType, o, outer); @@ -178,12 +177,11 @@ public class XmlParser extends ReaderParser { } private Map parseIntoMap(XmlParserSession session, XMLStreamReader r, Map m, ClassMeta keyType, ClassMeta valueType, BeanPropertyMeta pMeta) throws Exception { - BeanContext bc = session.getBeanContext(); int depth = 0; for (int i = 0; i < r.getAttributeCount(); i++) { String a = r.getAttributeLocalName(i); // TODO - Need better handling of namespaces here. - if (! (a.equals(bc.getBeanTypePropertyName()))) { + if (! (a.equals(session.getBeanTypePropertyName()))) { K key = session.trim(convertAttrToType(session, m, a, keyType)); V value = session.trim(convertAttrToType(session, m, r.getAttributeValue(i), valueType)); setName(valueType, value, key); @@ -204,7 +202,7 @@ public class XmlParser extends ReaderParser { if (o instanceof List) ((List)o).add(value); else - m.put(key, (V)new ObjectList(o, value).setBeanContext(bc)); + m.put(key, (V)new ObjectList(o, value).setBeanSession(session)); } else { m.put(key, value); } @@ -359,7 +357,6 @@ public class XmlParser extends ReaderParser { } private Object getUnknown(XmlParserSession session, XMLStreamReader r) throws Exception { - BeanContext bc = session.getBeanContext(); if (r.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("parser must be on START_ELEMENT to read next text", r.getLocation()); } @@ -367,11 +364,11 @@ public class XmlParser extends ReaderParser { // If this element has attributes, then it's always an ObjectMap. if (r.getAttributeCount() > 0) { - m = new ObjectMap(bc); + m = new ObjectMap(session); for (int i = 0; i < r.getAttributeCount(); i++) { String key = session.decodeString(r.getAttributeLocalName(i)); String val = r.getAttributeValue(i); - if (! key.equals(bc.getBeanTypePropertyName())) + if (! key.equals(session.getBeanTypePropertyName())) m.put(key, val); } } @@ -388,7 +385,7 @@ public class XmlParser extends ReaderParser { // Oops...this has an element in it. // Parse it as a map. if (m == null) - m = new ObjectMap(bc); + m = new ObjectMap(session); int depth = 0; do { int event = (eventType == -1 ? r.nextTag() : eventType); @@ -403,7 +400,7 @@ public class XmlParser extends ReaderParser { if (o instanceof ObjectList) ((ObjectList)o).add(value); else - m.put(key, new ObjectList(o, value).setBeanContext(bc)); + m.put(key, new ObjectList(o, value).setBeanSession(session)); } else { m.put(key, value); } @@ -436,28 +433,28 @@ public class XmlParser extends ReaderParser { //-------------------------------------------------------------------------------- @Override /* Parser */ - public XmlParserSession createSession(Object input, ObjectMap properties, Method javaMethod, Object outer) { - return new XmlParserSession(getContext(XmlParserContext.class), getBeanContext(), input, properties, javaMethod, outer); + public XmlParserSession createSession(Object input, ObjectMap op, Method javaMethod, Object outer, Locale locale, TimeZone timeZone) { + return new XmlParserSession(getContext(XmlParserContext.class), op, input, javaMethod, outer, locale, timeZone); } @Override /* Parser */ protected T doParse(ParserSession session, ClassMeta type) throws Exception { XmlParserSession s = (XmlParserSession)session; - type = s.getBeanContext().normalizeClassMeta(type); + type = session.normalizeClassMeta(type); return parseAnything(s, type, null, s.getXmlStreamReader(), s.getOuter(), true, null); } @Override /* ReaderParser */ protected Map doParseIntoMap(ParserSession session, Map m, Type keyType, Type valueType) throws Exception { XmlParserSession s = (XmlParserSession)session; - ClassMeta cm = s.getBeanContext().getMapClassMeta(m.getClass(), keyType, valueType); + ClassMeta cm = session.getMapClassMeta(m.getClass(), keyType, valueType); return parseIntoMap(s, m, cm.getKeyType(), cm.getValueType()); } @Override /* ReaderParser */ protected Collection doParseIntoCollection(ParserSession session, Collection c, Type elementType) throws Exception { XmlParserSession s = (XmlParserSession)session; - ClassMeta cm = s.getBeanContext().getCollectionClassMeta(c.getClass(), elementType); + ClassMeta cm = session.getCollectionClassMeta(c.getClass(), elementType); return parseIntoCollection(s,c, cm.getElementType()); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserContext.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserContext.java index 98592c1..6f1c010 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserContext.java +++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserContext.java @@ -39,60 +39,69 @@ import org.apache.juneau.parser.*; * *

    Configurable properties on the XML parser
    * - * + * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * *
    Setting nameDescriptionData typeDefault value
    Setting nameDescriptionData typeDefault valueSession overridable
    {@link #XML_xsiNs}XMLSchema-instance namespace URI.String"http://www.w3.org/2001/XMLSchema-instance"true
    {@link #XML_trimWhitespace}Trim whitespace from text elements.Booleantruetrue
    {@link #XML_validating}Enable validation.Booleanfalsetrue
    {@link #XML_coalescing}Enable text element coalescing.Booleanfalsetrue
    {@link #XML_replaceEntityReferences}Replace entity references.Booleantruetrue
    {@link #XML_reporter}XML reporter.{@link XMLReporter}nulltrue
    {@link #XML_resolver}XML resolver.{@link XMLResolver}nulltrue
    {@link #XML_eventAllocator}XML event allocator.{@link XMLEventAllocator}nulltrue
    {@link #XML_preserveRootElement}Preserve root element during generalized parsing.Booleanfalsetrue
    * @@ -113,6 +122,7 @@ public final class XmlParserContext extends ParserContext { *
  • Name: "XmlParser.xsiNs" *
  • Data type: String *
  • Default: "http://www.w3.org/2001/XMLSchema-instance" + *
  • Session-overridable: true * *

    * The XMLSchema namespace. @@ -126,6 +136,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.trimWhitespace" *
  • Data type: Boolean *
  • Default: true + *
  • Session-overridable: true * *

    * If true, whitespace in text elements will be automatically trimmed. @@ -139,6 +150,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.validating" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, XML document will be validated. @@ -153,6 +165,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.coalescing" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, XML text elements will be coalesced. @@ -167,6 +180,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.replaceEntityReferences" *
  • Data type: Boolean *
  • Default: true + *
  • Session-overridable: true * *

    * If true, entity references will be replace during parsing. @@ -181,6 +195,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.reporter" *
  • Data type: {@link XMLReporter} *
  • Default: null + *
  • Session-overridable: true * *

    * Associates an {@link XMLReporter} with this parser. @@ -196,6 +211,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.resolver" *
  • Data type: {@link XMLResolver} *
  • Default: null + *
  • Session-overridable: true * *

    * Associates an {@link XMLResolver} with this parser. @@ -209,6 +225,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.eventAllocator" *
  • Data type: {@link XMLEventAllocator} *
  • Default: null + *
  • Session-overridable: true * *

    * Associates an {@link XMLEventAllocator} with this parser. @@ -222,6 +239,7 @@ public final class XmlParserContext extends ParserContext { *

  • Name: "XmlParser.preserveRootElement" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, when parsing into a generic {@link ObjectMap}, the map will http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserSession.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserSession.java index d1bee00..5eadec4 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParserSession.java @@ -16,6 +16,7 @@ import static org.apache.juneau.xml.XmlParserContext.*; import java.io.*; import java.lang.reflect.*; +import java.util.*; import javax.xml.stream.*; import javax.xml.stream.util.*; @@ -48,7 +49,6 @@ public final class XmlParserSession extends ParserSession { * * @param ctx The context creating this session object. * The context contains all the configuration settings for this object. - * @param beanContext The bean context being used. * @param input The input. Can be any of the following types: *

      *
    • null @@ -61,9 +61,13 @@ public final class XmlParserSession extends ParserSession { * These override any context properties defined in the context. * @param javaMethod The java method that called this parser, usually the method in a REST servlet. * @param outer The outer object for instantiating top-level non-static inner classes. + * @param locale The session locale. + * If null, then the locale defined on the context is used. + * @param timeZone The session timezone. + * If null, then the timezone defined on the context is used. */ - public XmlParserSession(XmlParserContext ctx, BeanContext beanContext, Object input, ObjectMap op, Method javaMethod, Object outer) { - super(ctx, beanContext, input, op, javaMethod, outer); + public XmlParserSession(XmlParserContext ctx, ObjectMap op, Object input, Method javaMethod, Object outer, Locale locale, TimeZone timeZone) { + super(ctx, op, input, javaMethod, outer, locale, timeZone); if (op == null || op.isEmpty()) { xsiNs = ctx.xsiNs; trimWhitespace = ctx.trimWhitespace; @@ -175,13 +179,16 @@ public final class XmlParserSession extends ParserSession { * Silently closes the XML stream. */ @Override /* ParserContext */ - public void close() throws ParseException { - super.close(); - try { - if (xmlStreamReader != null) - xmlStreamReader.close(); - } catch (XMLStreamException e) { - // Ignore. + public boolean close() { + if (super.close()) { + try { + if (xmlStreamReader != null) + xmlStreamReader.close(); + } catch (XMLStreamException e) { + // Ignore. + } + return true; } + return false; } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/xml/XmlSchemaSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSchemaSerializer.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSchemaSerializer.java index 62dea11..a91ad29 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSchemaSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSchemaSerializer.java @@ -90,7 +90,7 @@ public class XmlSchemaSerializer extends XmlSerializer { /** * Returns an XML-Schema validator based on the output returned by {@link #doSerialize(SerializerSession, Object)}; * - * @param session The serializer session object return by {@link #createSession(Object, ObjectMap, Method)}.
      + * @param session The serializer session object return by {@link #createSession(Object, ObjectMap, Method, Locale, TimeZone)}.
      * Can be null. * @param o The object to serialize. * @return The new validator. @@ -186,7 +186,7 @@ public class XmlSchemaSerializer extends XmlSerializer { } private void process(SerializerSession session, Object o) throws IOException { - ClassMeta cm = session.getBeanContext().getClassMetaForObject(o); + ClassMeta cm = session.getClassMetaForObject(o); Namespace ns = defaultNs; if (cm == null) queueElement(ns, "null", object()); @@ -328,7 +328,6 @@ public class XmlSchemaSerializer extends XmlSerializer { int i = session.getIndent() + 1; cm = cm.getSerializedClassMeta(); - BeanContext bc = cm.getBeanContext(); w.oTag(i, "complexType") .attr("name", name); @@ -349,7 +348,7 @@ public class XmlSchemaSerializer extends XmlSerializer { if (session.isAddJsonTypeAttrs() || (session.isAddJsonStringTypeAttrs() && base.equals("string"))) { w.cTag().nl(); w.oTag(i+3, "attribute") - .attr("name", bc.getBeanTypePropertyName()) + .attr("name", session.getBeanTypePropertyName()) .attr("type", "string") .ceTag().nl(); w.eTag(i+2, "extension").nl(); @@ -489,7 +488,7 @@ public class XmlSchemaSerializer extends XmlSerializer { if (session.isAddBeanTypeProperties() || session.isAddJsonTypeAttrs()) { w.oTag(i+1, "attribute") - .attr("name", bc.getBeanTypePropertyName()) + .attr("name", session.getBeanTypePropertyName()) .attr("type", "string") .ceTag().nl(); } @@ -577,11 +576,11 @@ public class XmlSchemaSerializer extends XmlSerializer { } @Override /* Serializer */ - public XmlSerializerSession createSession(Object output, ObjectMap properties, Method javaMethod) { + public XmlSerializerSession createSession(Object output, ObjectMap op, Method javaMethod, Locale locale, TimeZone timeZone) { // This serializer must always have namespaces enabled. - if (properties == null) - properties = new ObjectMap(); - properties.put(XmlSerializerContext.XML_enableNamespaces, true); - return new XmlSerializerSession(getContext(XmlSerializerContext.class), getBeanContext(), output, properties, javaMethod); + if (op == null) + op = new ObjectMap(); + op.put(XmlSerializerContext.XML_enableNamespaces, true); + return new XmlSerializerSession(getContext(XmlSerializerContext.class), op, output, javaMethod, locale, timeZone); } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java index 83d9a3f..6836fbc 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java @@ -217,7 +217,6 @@ public class XmlSerializer extends WriterSerializer { * @throws SerializeException */ protected void findNsfMappings(XmlSerializerSession session, Object o) throws SerializeException { - BeanContext bc = session.getBeanContext(); ClassMeta aType = null; // The actual type aType = session.push(null, o, null); @@ -238,7 +237,7 @@ public class XmlSerializer extends WriterSerializer { if (aType.isBeanMap()) { bm = (BeanMap)o; } else if (aType.isBean()) { - bm = bc.forBean(o); + bm = session.toBeanMap(o); } else if (aType.isDelegate()) { ClassMeta innerType = ((Delegate)o).getClassMeta(); Namespace ns = innerType.getExtendedMeta(XmlClassMeta.class).getNamespace(); @@ -312,7 +311,6 @@ public class XmlSerializer extends WriterSerializer { ClassMeta eType, String elementName, Namespace elementNamespace, boolean addNamespaceUris, XmlFormat format, BeanPropertyMeta pMeta) throws Exception { - BeanContext bc = session.getBeanContext(); String ts = null; // The type string (e.g. or int indent = session.indent; // Current indentation ClassMeta aType = null; // The actual type @@ -342,12 +340,12 @@ public class XmlSerializer extends WriterSerializer { // Swap if necessary PojoSwap swap = aType.getPojoSwap(); if (swap != null) { - o = swap.swap(o, bc); + o = swap.swap(session, o); // If the getSwapClass() method returns Object, we need to figure out // the actual type now. if (sType.isObject()) - sType = bc.getClassMetaForObject(o); + sType = session.getClassMetaForObject(o); } } else { sType = eType.getSerializedClassMeta(); @@ -438,7 +436,7 @@ public class XmlSerializer extends WriterSerializer { if (typeName == null && elementName != null && session.isAddJsonTypeAttrs() && (session.isAddJsonStringTypeAttrs() || ! ts.equals("string"))) typeName = ts; if (typeName != null && ! typeName.equals(elementName)) - out.attr(dns, bc.getBeanTypePropertyName(), typeName); + out.attr(dns, session.getBeanTypePropertyName(), typeName); if (o == null) { if (! isNullTag) out.attr(xsi, "nil", "true"); @@ -472,7 +470,7 @@ public class XmlSerializer extends WriterSerializer { else if (sType.hasToObjectMapMethod()) hasChildren = serializeMap(session, out, sType.toObjectMap(o), sType); else if (sType.isBean()) - hasChildren = serializeBeanMap(session, out, bc.forBean(o), elementNamespace, isCollapsed); + hasChildren = serializeBeanMap(session, out, session.toBeanMap(o), elementNamespace, isCollapsed); else if (sType.isCollection() || (wType != null && wType.isCollection())) { if (isCollapsed) session.indent--; @@ -663,8 +661,8 @@ public class XmlSerializer extends WriterSerializer { } @Override /* Serializer */ - public XmlSerializerSession createSession(Object output, ObjectMap properties, Method javaMethod) { - return new XmlSerializerSession(getContext(XmlSerializerContext.class), getBeanContext(), output, properties, javaMethod); + public XmlSerializerSession createSession(Object output, ObjectMap op, Method javaMethod, Locale locale, TimeZone timeZone) { + return new XmlSerializerSession(getContext(XmlSerializerContext.class), op, output, javaMethod, locale, timeZone); } @Override /* CoreApi */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/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 8369796..4ee5b58 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 @@ -36,60 +36,69 @@ import org.apache.juneau.serializer.*; * *
      Configurable properties on the XML serializer
      * - * + * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * * * * * * + * * *
      Setting nameDescriptionData typeDefault value
      Setting nameDescriptionData typeDefault valueSession overridable
      {@link #XML_addJsonTypeAttrs}Add JSON type attributes to output.Booleanfalsetrue
      {@link #XML_addJsonStringTypeAttrs}Add JSON type attributes for strings to output.Booleanfalsetrue
      {@link #XML_enableNamespaces}Enable support for XML namespaces.Booleantruetrue
      {@link #XML_autoDetectNamespaces}Auto-detect namespace usage.Booleantruetrue
      {@link #XML_addNamespaceUrisToRoot}Add namespace URLs to the root element.Booleantruetrue
      {@link #XML_defaultNamespaceUri}Default namespace URI.Stringnulltrue
      {@link #XML_xsNamespace}XMLSchema namespace.{@link Namespace}{name:'xs',uri:'http://www.w3.org/2001/XMLSchema'}true
      {@link #XML_xsiNamespace}XMLSchema-Instance namespace.{@link Namespace}{name:'xsi',uri:'http://www.w3.org/2001/XMLSchema-instance'}true
      {@link #XML_namespaces}Default namespaces.Set<{@link Namespace}>empty settrue
      * @@ -110,6 +119,7 @@ public class XmlSerializerContext extends SerializerContext { *
    • Name: "XmlSerializer.addJsonTypeAttrs" *
    • Data type: Boolean *
    • Default: false + *
    • Session-overridable: true *
    *

    * If true, {@code type} attributes will be added to elements in the XML for number/boolean/null nodes. @@ -123,6 +133,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.addJsonStringTypeAttrs" *
  • Data type: Boolean *
  • Default: false + *
  • Session-overridable: true * *

    * If true, {@code type} attributes will be added to elements in the XML for string nodes. @@ -141,6 +152,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.enableNamespaces" *
  • Data type: Boolean *
  • Default: true + *
  • Session-overridable: true * *

    * If not enabled, XML output will not contain any namespaces regardless of any other settings. @@ -154,6 +166,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.autoDetectNamespaces" *
  • Data type: Boolean *
  • Default: true + *
  • Session-overridable: true * *

    * Detect namespace usage before serialization. @@ -182,6 +195,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.addNamespaceUrisToRoot" *
  • Data type: Boolean *
  • Default: true + *
  • Session-overridable: true * *

    * Use this setting to add {@code xmlns:x} attributes to the root @@ -198,6 +212,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.defaultNamespaceUri" *
  • Data type: String *
  • Default: null + *
  • Session-overridable: true * *

    * Specifies the default namespace URI for this document. @@ -211,6 +226,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.xsNamespace" *
  • Data type: {@link Namespace} *
  • Default: {name:'xs',uri:'http://www.w3.org/2001/XMLSchema'} + *
  • Session-overridable: true * *

    * Specifies the namespace for the XMLSchema namespace, used by the schema generated @@ -225,6 +241,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.xsiNamespace" *
  • Data type: {@link Namespace} *
  • Default: {name:'xsi',uri:'http://www.w3.org/2001/XMLSchema-instance'} + *
  • Session-overridable: true * *

    * Specifies the namespace of the XMLSchema-instance namespace used fornil=true attributes. @@ -238,6 +255,7 @@ public class XmlSerializerContext extends SerializerContext { *

  • Name: "XmlSerializer.namespaces" *
  • Data type: Set<{@link Namespace}> *
  • Default: empty set + *
  • Session-overridable: true * *

    * The default list of namespaces associated with this serializer. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/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 d097452..dfdd942 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 @@ -16,6 +16,7 @@ import static org.apache.juneau.xml.NamespaceFactory.*; import static org.apache.juneau.xml.XmlSerializerContext.*; import java.lang.reflect.*; +import java.util.*; import org.apache.juneau.*; import org.apache.juneau.internal.*; @@ -50,14 +51,17 @@ public class XmlSerializerSession extends SerializerSession { * * @param ctx The context creating this session object. * The context contains all the configuration settings for this object. - * @param beanContext The bean context being used. * @param output The output object. See {@link JsonSerializerSession#getWriter()} for valid class types. * @param op The override properties. * These override any context properties defined in the context. * @param javaMethod The java method that called this parser, usually the method in a REST servlet. + * @param locale The session locale. + * If null, then the locale defined on the context is used. + * @param timeZone The session timezone. + * If null, then the timezone defined on the context is used. */ - public XmlSerializerSession(XmlSerializerContext ctx, BeanContext beanContext, Object output, ObjectMap op, Method javaMethod) { - super(ctx, beanContext, output, op, javaMethod); + public XmlSerializerSession(XmlSerializerContext ctx, ObjectMap op, Object output, Method javaMethod, Locale locale, TimeZone timeZone) { + super(ctx, op, output, javaMethod, locale, timeZone); if (op == null || op.isEmpty()) { addJsonTypeAttrs = ctx.addJsonTypeAttrs; addJsonStringTypeAttrs = ctx.addJsonStringTypeAttrs; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/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 18d2fea..3eb2b90 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -675,13 +675,13 @@ /** Converts a Date object to an ISO8601 string. */ @Override - public String swap(Date o) { + public String swap(BeanSession session, Date o) { return format.format(o); } /** Converts an ISO8601 string to a Date object. */ @Override - public Date unswap(String o) throws ParseException { + public Date unswap(BeanSession session, String o, ClassMeta hint) throws ParseException { try { return format.parse(o); } catch (java.text.ParseException e) { @@ -1606,6 +1606,10 @@ Adding &plainText=true forces the response Content-Type to be text/plain.

    HTML
    +

    + Also, localization can be tested by passing in an Accept-Language header. +

    HTML/french
    +
    JSON
    XML
    @@ -3254,7 +3258,7 @@ .addPojoSwap( new PojoSwap<Person,Integer>() { @Override /* PojoSwap */ - public Integer swap(Person p) { + public Integer swap(BeanSession session, Person p) { return p.addresses.size(); } } @@ -4825,7 +4829,7 @@ public static class DoubleSwap extends PojoSwap<Double,String> { @Override /* PojoSwap */ - public String swap(Double o) throws SerializeException { + public String swap(BeanSession session, Double o) throws SerializeException { return FORMAT.format(o); } } @@ -4981,6 +4985,7 @@
    What's new in each release
      +
    • 6.0.2 (TBD)

    • 6.0.1 (TBD)

    • 6.0.0 (Oct 3, 2016)

    • 5.2.0.1 (Mar 23, 2016)

      @@ -5047,6 +5052,77 @@ + +

      6.0.2 (TBD)

      +
      +

      + Juneau 6.0.2 is a moderate update that provides localized serialization and parsing. + For example, dates can now be serialized to and parsed from locale-targeted formats. +

      +

      + In particular, this release cleans up the {@link org.apache.juneau.BeanContext} API to match + the {@link org.apache.juneau.ContextFactory}/{@link org.apache.juneau.Context}/{@link org.apache.juneau.Session} paradigm + previously used in the serializer and parser APIs. +

      + +
      org.apache.juneau
      +
        +
      • {@link org.apache.juneau.BeanContext} class split into separate {@link org.apache.juneau.BeanContext} and {@link org.apache.juneau.BeanSession} classes. +
          +
        • Session object meant to be single-use that can be discarded after use and contains session-level object cache and overridable Locale and TimeZone. +
        +
      • {@link org.apache.juneau.serializer.SerializerContext} and {@link org.apache.juneau.parser.ParserContext} + now extend directly from {@link org.apache.juneau.BeanContext}. +
      • {@link org.apache.juneau.serializer.SerializerSession} and {@link org.apache.juneau.parser.ParserSession} + now extend directly from {@link org.apache.juneau.BeanSession}. +
      • New settings in {@link org.apache.juneau.BeanContext}: +
          +
        • {@link org.apache.juneau.BeanContext#BEAN_debug} - Debug setting. Replaces individual debug properties in the serializer and parser contexts. +
        • {@link org.apache.juneau.BeanContext#BEAN_locale} - Specifies a default locale at the context level. +
        • {@link org.apache.juneau.BeanContext#BEAN_timeZone} - Specifies a default timezone at the context level. +
        +
      • Simplified {@link org.apache.juneau.transform.PojoSwap} class. Now just two methods: +
          +
        • {@link org.apache.juneau.transform.PojoSwap#swap(BeanSession,Object)} +
        • {@link org.apache.juneau.transform.PojoSwap#unswap(BeanSession,Object,ClassMeta)} +
        +
      • Several new {@link java.util.Calendar} and {@link java.util.Date} swaps: +
          +
        • {@link org.apache.juneau.transforms.CalendarSwap.ToString},{@link org.apache.juneau.transforms.DateSwap.ToString} - To {@link java.lang.String Strings} using the {@code Date.toString()} method. +
        • {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DT},{@link org.apache.juneau.transforms.DateSwap.ISO8601DT} - To ISO8601 date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTZ},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTZ} - Same as ISO8601DT, except always serializes in GMT. +
        • {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTP},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTP} - Same as ISO8601DT except with millisecond precision. +
        • {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTPZ},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTPZ} - Same as ISO8601DTZ except with millisecond precision. +
        • {@link org.apache.juneau.transforms.CalendarSwap.RFC2822DT},{@link org.apache.juneau.transforms.DateSwap.RFC2822DT} - To RFC2822 date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.RFC2822DTZ},{@link org.apache.juneau.transforms.DateSwap.RFC2822DTZ} - Same as RFC2822DT, except always serializes in GMT. +
        • {@link org.apache.juneau.transforms.CalendarSwap.RFC2822D},{@link org.apache.juneau.transforms.DateSwap.RFC2822D} - To RFC2822 date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateTimeSimple},{@link org.apache.juneau.transforms.DateSwap.DateTimeSimple} - To simple "yyyy/MM/dd HH:mm:ss" date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateSimple},{@link org.apache.juneau.transforms.DateSwap.DateSimple} - To simple "yyyy/MM/dd" date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.TimeSimple},{@link org.apache.juneau.transforms.DateSwap.TimeSimple} - To simple "HH:mm:ss" time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateFull},{@link org.apache.juneau.transforms.DateSwap.DateFull} - To {@link java.text.DateFormat#FULL} date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateLong},{@link org.apache.juneau.transforms.DateSwap.DateLong} - To {@link java.text.DateFormat#LONG} date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateMedium},{@link org.apache.juneau.transforms.DateSwap.DateMedium} - To {@link java.text.DateFormat#MEDIUM} date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateShort},{@link org.apache.juneau.transforms.DateSwap.DateShort} - To {@link java.text.DateFormat#SHORT} date strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.TimeFull},{@link org.apache.juneau.transforms.DateSwap.TimeFull} - To {@link java.text.DateFormat#FULL} time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.TimeLong},{@link org.apache.juneau.transforms.DateSwap.TimeLong} - To {@link java.text.DateFormat#LONG} time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.TimeMedium},{@link org.apache.juneau.transforms.DateSwap.TimeMedium} - To {@link java.text.DateFormat#MEDIUM} time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.TimeShort},{@link org.apache.juneau.transforms.DateSwap.TimeShort} - To {@link java.text.DateFormat#SHORT} time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateTimeFull},{@link org.apache.juneau.transforms.DateSwap.DateTimeFull} - To {@link java.text.DateFormat#FULL} date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateTimeLong},{@link org.apache.juneau.transforms.DateSwap.DateTimeLong} - To {@link java.text.DateFormat#LONG} date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateTimeMedium},{@link org.apache.juneau.transforms.DateSwap.DateTimeMedium} - To {@link java.text.DateFormat#MEDIUM} date-time strings. +
        • {@link org.apache.juneau.transforms.CalendarSwap.DateTimeShort},{@link org.apache.juneau.transforms.DateSwap.DateTimeShort} - To {@link java.text.DateFormat#SHORT} date-time strings. +
        +
      + +
      org.apache.juneau.server
      +
        +
      • {@link org.apache.juneau.server.RestRequest} now passes locale and timezone to serializers/parsers/transforms. +
      • New {@link org.apache.juneau.server.RestRequest#getTimeZone()} method. +
      +
      + + +

      6.0.1 (TBD)

      @@ -5153,7 +5229,7 @@
    • Serializers and parsers now automatically convert {@link java.lang.Class} objects to readable names via {@link org.apache.juneau.internal.ClassUtils#getReadableClassName(Class)}.
    • Eliminated the ClassFilter class since it's no longer needed.
    • Code and concurrency improvements to {@link org.apache.juneau.serializer.SerializerGroup} and {@link org.apache.juneau.parser.ParserGroup}. -
    • Various enhancements to {@link org.apache.juneau.BeanContext#convertToType(Object,Class)}. +
    • Various enhancements to BeanContext.convertToType(Object,Class).
    • New properties on {@link org.apache.juneau.html.HtmlSerializer}:
      • {@link org.apache.juneau.html.HtmlSerializerContext#HTML_detectLinksInStrings} - Automatically detect hyperlinks in strings. @@ -6420,7 +6496,7 @@

        • Improved error handling. -
        • New {@link org.apache.juneau.parser.ParserContext#PARSER_debug} and {@link org.apache.juneau.serializer.SerializerContext#SERIALIZER_debug} +
        • New ParserContext.PARSER_debug and SerializerContext.SERIALIZER_debug. settings for logging additional information for debugging problems.
        • New {@link org.apache.juneau.serializer.SerializerContext#SERIALIZER_ignoreRecursions} setting for explicitely ignoring recursions when serializing models. Previously, the SERIALIZER_detectRecursions setting did this, but now it simply looks for recursions @@ -6642,7 +6718,7 @@
        • Removed lazy-initialization that required locking in {@link org.apache.juneau.ClassMeta}.
        • New BeanContext.setDefaultParser(ReaderParser) method added for specifying a default parser to use in a bean context (used when converting beans to Strings using - {@link org.apache.juneau.BeanContext#convertToType(Object,Class)}). + BeanContext.convertToType(Object,Class). Old behavior simply used the default JSON serializer in these cases.
        • More consistent handling of exceptions across all parsers.
        • Minor changes to {@link org.apache.juneau.server.RestRequest} class. @@ -7867,7 +7943,7 @@ See {@link org.apache.juneau.server.RestServlet} for more information.
        • - Enhancements to {@link org.apache.juneau.BeanContext#convertToType(Object,Class)} to be able to convert Strings to classes with + Enhancements to BeanContext.convertToType(Object,Class) to be able to convert Strings to classes with fromString(String)/valueOf(String) static methods or T(String) constructors.
        http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bb650bde/juneau-core/src/test/java/org/apache/juneau/AnnotationsTest.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/AnnotationsTest.java b/juneau-core/src/test/java/org/apache/juneau/AnnotationsTest.java index 70ac5ef..378f088 100755 --- a/juneau-core/src/test/java/org/apache/juneau/AnnotationsTest.java +++ b/juneau-core/src/test/java/org/apache/juneau/AnnotationsTest.java @@ -27,11 +27,11 @@ public class AnnotationsTest { //==================================================================================================== @Test public void testBeanWithExplicitProperties() throws Exception { - BeanContext bc = BeanContext.DEFAULT; + BeanSession session = BeanContext.DEFAULT.createSession(); BeanMap bm = null; // Basic test - bm = bc.newBeanMap(Person1.class).load("{age:21,name:'foobar'}"); + bm = session.newBeanMap(Person1.class).load("{age:21,name:'foobar'}"); assertNotNull(bm); assertNotNull(bm.getBean()); assertEquals(bm.get("age"), 21); @@ -61,11 +61,11 @@ public class AnnotationsTest { //==================================================================================================== @Test public void testForOnlyPublicFields() throws Exception { - BeanContext bc = BeanContext.DEFAULT; + BeanSession session = BeanContext.DEFAULT.createSession(); BeanMap bm = null; // Make sure only public fields are detected - bm = bc.newBeanMap(A.class).load("{publicField:123}"); + bm = session.newBeanMap(A.class).load("{publicField:123}"); assertNotNull("F1", bm); assertNotNull("F2", bm.getBean()); assertObjectEquals("{publicField:123}", bm.getBean());