Search code examples
spring-bootjpaspring-data-jpasapui5olingo

Olingo returns DateTime or Timestamp values in a wrong format


I made an odata service with Olingo2/JPA and spring-boot based on this GitHub repository.

The problem is olingo does not return the date/time or timestamp columns in a correct format as defined in Odata standard (or maybe Microsoft standard). I mean my front-end library (i.e. OpenUI5) expects some value like <d:ValidFrom>/Date(1579075200000)/</d:ValidFrom> for Edm.DateTime column but what olingo returns is <d:ValidFrom>2020-01-15T08:00:00</d:ValidFrom> which is not accepted by OpenUI5!

What is your suggestion?

1- Is there a way that I force Olingo to return data/time or timestamp in the format that Microsoft defined or not? (i.e. /Date(timestamp)/)

2- Is there a way that OpenUI5 accept the date\time in a format like yyyy-MM-ddTHH:mm:ss ?


Solution

  • As I discussed with @Marc in the comments, olingo in XML format returns the data\time or timestamp columns in the format of yyyy-MM-ddTHH:mm:ss:

    date format in odata via xml

    as soon as we request the output in the JSON format by passing ?$format=json in the URL, the data\time values will be return in the format of timestamp, while the value is enclosed by /Date() string to show it is a data/time value. (This standard is defined by Microsoft!)

    date format in odata via json

    In UI5 if you are going to store the data for feeding to your mock server it is needed to store the data in JSON file and obviously the date\time values must be stored like /Date(timestamp).