Class UrlParamSerializer

java.lang.Object
io.jmix.flowui.view.navigation.UrlParamSerializer

@Component("flowui_UrlParamSerializer") public class UrlParamSerializer extends Object
The utility class that is responsible for serializing and deserializing various data types into string representations suitable for URL parameters.

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 Details

  • Constructor Details

  • Method Details

    • initFormatters

      protected void initFormatters()
    • serialize

      public String serialize(Object value)
      Serializes the given value to 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

      protected String serializeDateTime(Date value)
    • serializeLocalDate

      protected String serializeLocalDate(LocalDate value)
    • serializeLocalDateTime

      protected String serializeLocalDateTime(LocalDateTime value)
    • serializeDate

      protected String serializeDate(Date value)
    • serializeOffsetDateTime

      protected String serializeOffsetDateTime(OffsetDateTime value)
    • serializeLocalTime

      protected String serializeLocalTime(LocalTime value)
    • serializeOffsetTime

      protected String serializeOffsetTime(OffsetTime value)
    • serializeTime

      protected String serializeTime(Time value)
    • serializeEnum

      protected String serializeEnum(Enum<?> value)
    • serializePrimitive

      protected String serializePrimitive(Object value)
    • serializeText

      protected String serializeText(Object value)
    • serializeUuid

      protected String serializeUuid(UUID value)
    • serializeComposite

      protected String serializeComposite(Object value)
    • serializeCollection

      protected String serializeCollection(Collection<?> value)
    • serializeDateInterval

      protected String serializeDateInterval(BaseDateInterval value)
    • deserialize

      public <T> T deserialize(Class<T> type, String serializedValue)
      Deserializes the given serializedValue as a value with given type.

      String, Integer, Long and UUID ids are only supported.

      Parameters:
      type - value type
      serializedValue - serialized value
      Returns:
      deserialized value
      Throws:
      IllegalArgumentException - if null value and/or type are passed or the given value type is not supported
    • parseOffsetDateTime

      protected OffsetDateTime parseOffsetDateTime(String stringValue)
    • parseOffsetTime

      protected OffsetTime parseOffsetTime(String stringValue)
    • parseBigDecimal

      protected BigDecimal parseBigDecimal(String stringValue)
    • parseBigInteger

      protected BigInteger parseBigInteger(String stringValue)
    • parseCharacter

      protected Character parseCharacter(String stringValue)
    • parseDate

      protected Date parseDate(String stringValue)
    • parseDateTime

      protected Date parseDateTime(String stringValue)
    • parseDouble

      protected Double parseDouble(String stringValue)
    • parseEnum

      protected <T> T parseEnum(Class<T> type, String stringValue)
    • parseFloat

      protected Float parseFloat(String stringValue)
    • parseLocalDate

      protected LocalDate parseLocalDate(String stringValue)
    • parseLocalDateTime

      protected LocalDateTime parseLocalDateTime(String stringValue)
    • parseLocalTime

      protected LocalTime parseLocalTime(String stringValue)
    • parseShort

      protected Short parseShort(String stringValue)
    • parseTime

      protected Time parseTime(String stringValue)
    • parseBoolean

      protected Boolean parseBoolean(String stringValue)
    • parseString

      protected String parseString(String stringValue)
    • parseInteger

      protected Integer parseInteger(String stringValue)
    • parseUri

      protected URI parseUri(String stringValue)
    • parseLong

      protected Long parseLong(String stringValue)
    • parseUuid

      protected UUID parseUuid(String stringValue)
    • parseComposite

      protected <T> T parseComposite(Class<T> type, String stringValue)
    • parseDateInterval

      protected Object parseDateInterval(String stringValue)
    • propertyNameMapper

      protected String propertyNameMapper(String property)
    • propertyValueMapper

      protected String propertyValueMapper(String property)
    • escape

      protected String escape(String value)
      Escapes the given value if 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 with getEscapeChar() followed by two hexadecimal digits of its code, e.g. foo/bar is escaped to ~~foo~2Fbar. Unsafe characters are listed by getUnsafeChars().

      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

      protected String unescape(String value)
      Unescapes the given value if it was escaped by escape(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

      protected boolean isEscapingRequired(String value)
      Checks whether the given value must be escaped to be used in a URL.
      Parameters:
      value - a value to check
      Returns:
      true if 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:
      true if the character is unsafe
    • getUnsafeChars

      protected String 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 %2F is 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_CHARS by default
    • getEscapeChar

      protected char getEscapeChar()
      Returns:
      the character that starts an escape sequence, ESCAPE_CHAR by default
    • getEscapedValuePrefix

      protected String getEscapedValuePrefix()
      Returns:
      the prefix that marks a value containing escape sequences, ESCAPED_VALUE_PREFIX by default