Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are a few special coercions related to null there; Object --> List wraps a lone object as a singleton list, we then need null --> List to ensure that null stays null (rather than a singleton list whose lone element is a null).

Type

...

Coercion Interpolation

Tapestry will try to interpolate necessary coercions. For example, say it is necessary to coerce a StringBuffer to an Integer; the TypeCoercer service will chain together a series of coercions:

...

With Java 8, the Java Time API (JSR310) got added to the JDK, providing a new, more straightforward way of dealing with date and time. The multitude of different types created a need for additional TypeCoercers. But due to the way the Java Time API was implemented, you must be aware of some edge cases and intricacies.

Milliseconds Precision

Even though the Java Time API partially supports nanosecond precision, it's not guaranteed. Actually, the OS / the JVM implementation is responsible for providing the current time with java.time.Clock. Most of the new types even don't have convenience-methods for a nanosecond-based representation.

All date(time)-based types use java.time.Instant for coercion, which itself is coerced with milliseconds precision. This provides compatibility with java.util.Date#getTime(), which is also milliseconds-based.

Nanoseconds Precision

The 2 types not using milliseconds are not subclasses of or convertible to java.time.Instant:

  • java.time.LocalTime: Uses nanoseconds internally, and no convenience method for milliseconds exists.
  • java.time.Duration: Uses nanoseconds and seconds internally. Even though a convenience method for milliseconds exists, the type isn't dependent on the OS/JVM precision. So the highest possible precision is used.
Timezones

The Java Time API supports timezone-less types, e.g. java.time.LocalDate, java.time.LocalDateTime.
However, coercing these types into a `java.time.Instant` requires a timezone, because java.time.Instant uses the unix timestamp 0 as reference.

...

Additionally, java.time.LocalDate we use the local time of 00:00 for it's coercion to java.time.Instant.

Invalid Coercion Paths

Due to the powerful feature of finding compatible TypeCoercer paths to convert types with no explicit TypeCoercer, some additional TypeCoercers were added to ensure the correct conversion between types.

...