Class UrlParamSerializer
Text values are escaped if they contain characters that cannot be used in a value of a single
URL path segment or query parameter, see escape(String).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DateIntervalSupportstatic final Stringstatic final Stringstatic final Stringstatic final charThe default character that starts an escape sequence of a text URL parameter.protected static final intstatic final StringThe default prefix that marks a text URL parameter containing escape sequences.protected static final Stringprotected Metadataprotected MetadataToolsprotected UiNavigationPropertiesprotected DateTimeFormatterprotected DateTimeFormatterprotected DateTimeFormatterprotected DateTimeFormatterprotected DateTimeFormatterprotected static final StringThe default characters that cannot be used in a value of a URL path segment. -
Constructor Summary
ConstructorsConstructorDescriptionUrlParamSerializer(UiNavigationProperties navigationProperties, MetadataTools metadataTools, Metadata metadata, DateIntervalSupport dateIntervalSupport) -
Method Summary
Modifier and TypeMethodDescription<T> Tdeserialize(Class<T> type, String serializedValue) Deserializes the givenserializedValueas a value with giventype.protected StringEscapes the givenvalueif it cannot be used in a URL as is.protected charprotected Stringprotected StringReturns characters that cannot be used in a value of a URL path segment.protected voidprotected booleanisEscapingRequired(String value) Checks whether the givenvaluemust be escaped to be used in a URL.protected booleanisUnsafe(char c) Checks whether the given character cannot be used in a URL as is.protected BigDecimalparseBigDecimal(String stringValue) protected BigIntegerparseBigInteger(String stringValue) protected BooleanparseBoolean(String stringValue) protected CharacterparseCharacter(String stringValue) protected <T> TparseComposite(Class<T> type, String stringValue) protected Dateprotected ObjectparseDateInterval(String stringValue) protected DateparseDateTime(String stringValue) protected DoubleparseDouble(String stringValue) protected <T> Tprotected FloatparseFloat(String stringValue) protected IntegerparseInteger(String stringValue) protected LocalDateparseLocalDate(String stringValue) protected LocalDateTimeparseLocalDateTime(String stringValue) protected LocalTimeparseLocalTime(String stringValue) protected Longprotected OffsetDateTimeparseOffsetDateTime(String stringValue) protected OffsetTimeparseOffsetTime(String stringValue) protected ShortparseShort(String stringValue) protected StringparseString(String stringValue) protected Timeprotected URIprotected UUIDprotected StringpropertyNameMapper(String property) protected StringpropertyValueMapper(String property) Serializes the givenvalueto string representation.protected StringserializeCollection(Collection<?> value) protected StringserializeComposite(Object value) protected StringserializeDate(Date value) protected Stringprotected StringserializeDateTime(Date value) protected StringserializeEnum(Enum<?> value) protected StringserializeLocalDate(LocalDate value) protected Stringprotected StringserializeLocalTime(LocalTime value) protected Stringprotected StringserializeOffsetTime(OffsetTime value) protected StringserializePrimitive(Object value) protected StringserializeText(Object value) protected StringserializeTime(Time value) protected StringserializeUuid(UUID value) protected StringUnescapes the givenvalueif it was escaped byescape(String).
-
Field Details
-
ESCAPE_CHAR
public static final char ESCAPE_CHARThe default character that starts an escape sequence of a text URL parameter.- See Also:
-
ESCAPED_VALUE_PREFIX
The default prefix that marks a text URL parameter containing escape sequences.- See Also:
-
DEFAULT_DATE_FORMAT
- See Also:
-
DEFAULT_TIME_FORMAT
- See Also:
-
DEFAULT_OFFSET_FORMAT
- See Also:
-
UNSAFE_CHARS
The default characters that cannot be used in a value of a URL path segment.- See Also:
-
HEX_DIGITS
- See Also:
-
ESCAPE_SEQUENCE_LENGTH
protected static final int ESCAPE_SEQUENCE_LENGTH- See Also:
-
temporalDateFormatter
-
temporalTimeFormatter
-
temporalDateTimeFormatter
-
temporalOffsetDateTimeFormatter
-
temporalOffsetTimeFormatter
-
metadataTools
-
metadata
-
dateIntervalSupport
-
-
Constructor Details
-
Method Details
-
initFormatters
protected void initFormatters() -
serialize
Serializes the givenvalueto string representation.String, Integer, Long and UUID values are only supported.
- Parameters:
value- value to serialize- Returns:
- serialized string representation of given value
- Throws:
IllegalArgumentException- if null value is passed or it has an unsupported type
-
serializeDateTime
-
serializeLocalDate
-
serializeLocalDateTime
-
serializeDate
-
serializeOffsetDateTime
-
serializeLocalTime
-
serializeOffsetTime
-
serializeTime
-
serializeEnum
-
serializePrimitive
-
serializeText
-
serializeUuid
-
serializeComposite
-
serializeCollection
-
serializeDateInterval
-
deserialize
Deserializes the givenserializedValueas a value with giventype.String, Integer, Long and UUID ids are only supported.
- Parameters:
type- value typeserializedValue- serialized value- Returns:
- deserialized value
- Throws:
IllegalArgumentException- if null value and/or type are passed or the given value type is not supported
-
parseOffsetDateTime
-
parseOffsetTime
-
parseBigDecimal
-
parseBigInteger
-
parseCharacter
-
parseDate
-
parseDateTime
-
parseDouble
-
parseEnum
-
parseFloat
-
parseLocalDate
-
parseLocalDateTime
-
parseLocalTime
-
parseShort
-
parseTime
-
parseBoolean
-
parseString
-
parseInteger
-
parseUri
-
parseLong
-
parseUuid
-
parseComposite
-
parseDateInterval
-
propertyNameMapper
-
propertyValueMapper
-
escape
Escapes the givenvalueif it cannot be used in a URL as is.A value that contains no unsafe characters is returned unchanged. Otherwise the whole value is prefixed with
getEscapedValuePrefix()and every unsafe character is replaced withgetEscapeChar()followed by two hexadecimal digits of its code, e.g.foo/baris escaped to~~foo~2Fbar. Unsafe characters are listed bygetUnsafeChars().The prefix keeps escaping backward compatible:
unescape(String)processes only values that carry it, so URLs created before escaping was introduced are parsed exactly as before.Percent-encoding is not used on purpose: a servlet container decodes percent-encoded sequences before Vaadin resolves route parameters, so an encoded value would be indistinguishable from a raw one. Besides, Tomcat 10.1 and later reject requests containing encoded slashes in the path.
getEscapeChar()belongs to the unreserved set of RFC 3986 and thus is left as is by both browsers and servlet containers, unlike%which the transport layer would consume.- Parameters:
value- a value to escape- Returns:
- the escaped value, or the given value if escaping is not required
-
unescape
Unescapes the givenvalueif it was escaped byescape(String).A value without
getEscapedValuePrefix()is returned as is, which keeps URLs created before escaping was introduced readable.- Parameters:
value- a value to unescape- Returns:
- the unescaped value, or the given value if it is not escaped
-
isEscapingRequired
Checks whether the givenvaluemust be escaped to be used in a URL.- Parameters:
value- a value to check- Returns:
trueif the value contains unsafe characters or can be mistaken for an escaped value
-
isUnsafe
protected boolean isUnsafe(char c) Checks whether the given character cannot be used in a URL as is.- Parameters:
c- a character to check- Returns:
trueif the character is unsafe
-
getUnsafeChars
Returns characters that cannot be used in a value of a URL path segment.Only path separators are unsafe by default. Both
/and\are separators: a browser normalizes a backslash to a forward slash, so it splits the path segment as well.Query parameters need no escaping here, because Vaadin encodes and decodes their values on its own. Other delimiters survive a path segment, as the browser percent-encodes them and the servlet container decodes them back, while
%2Fis rejected by Tomcat 10.1 and later.The escape character returned by
getEscapeChar()is not included: on its own it doesn't break a URL, so a value containing it is not escaped. It is escaped only inside an already escaped value, to keep escape sequences unambiguous.Values escaped by an overridden character set remain readable by
unescape(String), because unescaping is driven by escape sequences rather than by the character set.- Returns:
- unsafe characters,
UNSAFE_CHARSby default
-
getEscapeChar
protected char getEscapeChar()- Returns:
- the character that starts an escape sequence,
ESCAPE_CHARby default
-
getEscapedValuePrefix
- Returns:
- the prefix that marks a value containing escape sequences,
ESCAPED_VALUE_PREFIXby default
-