I've got ODM 8.9.1 Rule Designer running on a Java 8 vm. Java.time.* types show up in the XOM but are not recognized in the BOM. For example, a java.time.LocalDate shows "cannot be verbalized" and cannot be found in the Ctrl-Shift-Space verbal completion choices. I've got my XOM on Java 8. How do I get my BOM to Java 8?
2 Answers
One way to get your BOM using Java 8 dates is to create a helper method in your XOM that takes the verbalized java.util.Date and convert this to a java.time.LocalDateTime For example,
public static int compareDates(Date date1, Date date2) {
LocalDateTime newDate1 = date1.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime newDate2 = date2.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() ;
return newDate1.compareTo(newDate2);
}

- 11
- 2
While ODM 8.10 has been available for some time and includes native support for the java.time
package, I am stuck using ODM 8.9.1 for a while longer. Here is how I was able to use java.time.LocalDate
and java.time.ZonedDateTime
in my ODM 8.9.1 Rule Apps.
I manually created a new BOM Entry in my BOM project and manually added the java.time.LocalDate
and java.time.ZonedDateTime
classes with no members. I am able to verbalize LocalDate
, but not ZonedDateTime
. Rule Designer reports no errors or warnings, and I am able to build and execute just fine. As long as I stay away from BOM Update, defining these classes in the BOM works fine.
I have custom classes with data members of type ZonedDateTime
. These are in a separate BOM Entry from the java time classes. I can verbalize those members and use them as expected with my custom methods, which accept parameters and return values of type ZonedDateTime
.
Here is the glitch: Those ZonedDateTime
members show up in the Vocabulary view as being of System type 'date'
and are proposed in the Intellirule editor for the System 'date'
operations. As expected, using one of these operations in a rule produces an error, but the error is visible only in the ARL tap, and not in the Intellirule tab or the Problems view.
I'm not sure how or why RD determined that those members are of type 'date'
. I'm hoping to find a way to turn off the System verbalizations related to 'date'
. Meanwhile, I just avoid using the System 'date'
operations and my Rule Apps execute just fine. And when we do finally switch to ODM 8.10, I'll be ready to go.
Now, about HTDS and REST and JSON. The Swagger for java.util.Date
uses the format "date-time". The Swagger for java.time.ZonedDateTime
also uses "date-time", while for java.time.LocalDate
it uses "date". So java.time.ZonedDateTime
is a direct replacement for java.util.Date
without affecting the calling apps. But you must use a custom deserializer to make it work, which involves a couple steps:
In the class where you define you data member, you must use an annotation:
@JsonDeserialize(using = CustomZonedDateTimeDeserializer.class)
private ZonedDateTime yourDateMember;
And you must define a that custom deserializer class:
@NotBusiness
public class CustomZonedDateTimeDeserializer extends StdDeserializer<ZonedDateTime> {
private static final long serialVersionUID = -3569126727040924932L;
public CustomZonedDateTimeDeserializer() {
this(null);
}
public CustomZonedDateTimeDeserializer(final Class<?> vc) {
super(vc);
}
@Override
public ZonedDateTime deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException {
final String dateStr = jsonparser.getText();
try {
return ZonedDateTime.parse(dateStr);
} catch (final Exception e) {
return null; // Parsing of the date failed, continue processing of the request with null value for the date
}
}
}

- 164
- 9