@Override /* Context */ public UrlEncodingSerializerBuilder builder() { return new UrlEncodingSerializerBuilder(getPropertyStore()); }
/** * Configuration property: Serialize bean property collections/arrays as separate key/value pairs. * * @see UrlEncodingSerializer#URLENC_expandedParams * @return * <jk>false</jk> if serializing the array <code>[1,2,3]</code> results in <code>?key=$a(1,2,3)</code>. * <br><jk>true</jk> if serializing the same array results in <code>?key=1&key=2&key=3</code>. */ protected final boolean isExpandedParams() { return ctx.isExpandedParams(); } }
@Override /* HttpServletRequest */ public ServletInputStream getInputStream() throws IOException { if (formDataMap != null) body = UrlEncodingSerializer.DEFAULT.toString(formDataMap).getBytes(); return new BoundedServletInputStream(new ByteArrayInputStream(body), Integer.MAX_VALUE); }
/** * Creates the URL-encoding serializer used for serializing object passed to {@link Redirect}. * <p> * Subclasses can override this method to provide their own specialized serializer. * * @param properties Servlet-level properties returned by {@link #createProperties()}. * @param beanFilters Servlet-level bean filters returned by {@link #createBeanFilters()}. * @param pojoSwaps Servlet-level POJO swaps returned by {@link #createPojoSwaps()}. * @return The new URL-Encoding serializer. * @throws Exception If the serializer could not be constructed for any reason. */ protected UrlEncodingSerializer createUrlEncodingSerializer(ObjectMap properties, Class<?>[] beanFilters, Class<?>[] pojoSwaps) throws Exception { return new UrlEncodingSerializer().setProperties(properties).addBeanFilters(beanFilters).addPojoSwaps(pojoSwaps); }
@Test public void testUrlEncoding() throws Exception { UrlEncodingSerializer s = UrlEncodingSerializer.create().pojoSwaps(ReaderSwap.PlainText.class).build(); Reader r; Map<String,Object> m; r = new StringReader("foo=bar&baz=quz"); m = new HashMap<>(); m.put("X", r); assertEquals("X='foo=bar%26baz=quz'", s.serialize(m)); } }
accept ); expandedParams = getBooleanProperty(URLENC_expandedParams, false);
@Test public void e1_testUrlEncodingSerialize() throws Exception { Serializer s = UrlEncodingSerializer.create().uriContext(input.context).uriResolution(input.resolution).uriRelativity(input.relativity).build(); testSerialize(s, results.urlEncoding); }
@Test public void e11_serializeUrlEncoding() throws Exception { WriterSerializer s = UrlEncodingSerializer.DEFAULT_READABLE.builder().maxIndent(input.maxDepth).build(); testSerialize("urlEncoding", s, input.urlEnc); }
context = ContextFactory.create().setProperties(properties).getContext(RestServletContext.class); beanContext = createBeanContext(properties, beanFilters, pojoSwaps); urlEncodingSerializer = createUrlEncodingSerializer(properties, beanFilters, pojoSwaps).lock(); urlEncodingParser = createUrlEncodingParser(properties, beanFilters, pojoSwaps).lock(); serializers = createSerializers(properties, beanFilters, pojoSwaps).lock();
accept ); expandedParams = getBooleanProperty(URLENC_expandedParams, false);
@Test public void e2_testUrlEncodingParse() throws Exception { Serializer s = UrlEncodingSerializer.create().uriContext(input.context).uriResolution(input.resolution).uriRelativity(input.relativity).build(); testParse(s, UrlEncodingParser.DEFAULT); }
@Test public void testPlainTextParams() throws Exception { WriterSerializer s = UrlEncodingSerializer.DEFAULT.builder().paramFormatPlain().build(); assertEquals("_value=foo", s.serialize("foo")); assertEquals("_value='foo'", s.serialize("'foo'")); assertEquals("_value=(foo)", s.serialize("(foo)")); assertEquals("_value=@(foo)", s.serialize("@(foo)")); Map<String,Object> m = new AMap<String,Object>() .append("foo", "foo") .append("'foo'", "'foo'") .append("(foo)", "(foo)") .append("@(foo)", "@(foo)"); assertEquals("foo=foo&'foo'='foo'&(foo)=(foo)&@(foo)=@(foo)", s.serialize(m)); List<String> l = new AList<String>().appendAll("foo", "'foo'", "(foo)", "@(foo)"); assertEquals("0=foo&1='foo'&2=(foo)&3=@(foo)", s.serialize(l)); A a = new A(); assertEquals("'foo'='foo'&(foo)=(foo)&@(foo)=@(foo)&foo=foo", s.serialize(a)); }
@Override /* HttpServletRequest */ public ServletInputStream getInputStream() throws IOException { if (formDataMap != null) body = UrlEncodingSerializer.DEFAULT.toString(formDataMap).getBytes(); return new BoundedServletInputStream(new ByteArrayInputStream(body), Integer.MAX_VALUE); }
/** * Configuration property: Serialize bean property collections/arrays as separate key/value pairs. * * @see UrlEncodingSerializer#URLENC_expandedParams * @return * <jk>false</jk> if serializing the array <code>[1,2,3]</code> results in <code>?key=$a(1,2,3)</code>. * <br><jk>true</jk> if serializing the same array results in <code>?key=1&key=2&key=3</code>. */ protected final boolean isExpandedParams() { return ctx.isExpandedParams(); } }
@Override /* Context */ public UrlEncodingSerializerBuilder builder() { return new UrlEncodingSerializerBuilder(getPropertyStore()); }
accept ); expandedParams = getBooleanProperty(URLENC_expandedParams, false);
assertEquals(e, r); s = UrlEncodingSerializer.create().pojoSwaps(getPojoSwaps()).trimNullProperties(false).build(); e = "AQID=a&BAUG=null&null=b"; r = s.serialize(t);
@Test public void testTrimNullsFromBeans() throws Exception { UrlEncodingSerializerBuilder s = UrlEncodingSerializer.create(); A t1 = A.create(), t2; s.trimNullProperties(false); String r = s.build().serialize(t1); assertEquals("s1=null&s2=s2", r); t2 = p.parse(r, A.class); assertEqualObjects(t1, t2); s.trimNullProperties(true); r = s.build().serialize(t1); assertEquals("s2=s2", r); t2 = p.parse(r, A.class); assertEqualObjects(t1, t2); }