Skip to main content

About OData's Data Types

The data types in OData V2 are a mess regarding date and time types. But hey, that's somehow true even for major languages like Java before a certain version (when Joda was still with us).

This page is dedicated to list the data types for V2 and V4, contrast them with each other and illustrate them with examples; yeah well, and rant a bit about specification flaws at the end.

Here are the main differences between V2 and V4 data types:

OData TypeV2Format (V2)V4Format (V4)
Edm.Stringstringstring
Edm.Booleanbooleantrue / falsebooleantrue / false
Edm.Int16numbere.g. 42numbere.g. 42
Edm.Int32numbere.g. 123456numbere.g. 123456
Edm.Bytestringe.g. "255"numbere.g. 255
Edm.SBytestringe.g. "-128"numbere.g. -128
Edm.Int64stringe.g. "9007199254740993"numbere.g. 9007199254740993
Edm.Singlestringe.g. "3.14"numbere.g. 3.14
Edm.Doublestringe.g. "3.1415926535"numbere.g. 3.1415926535
Edm.Decimalstringe.g. "123.45"numbere.g. 123.45
Edm.BinarystringBase64-encoded stringstringBase64-encoded string
Edm.StreamStream access, not represented as JS value
Edm.DateTimeOffsetstring/Date(<milliseconds>±HHmm)/, e.g. /Date(1672485300000+0100)/stringISO 8601 date-time with offset, e.g. 2022-12-31T12:15:00+01:00
Edm.Datestringyyyy-MM-dd, e.g. 2022-12-31
Edm.TimeOfDaystringHH:mm:ss[.fffffff], e.g. 12:15:00
Edm.DurationstringISO 8601 duration, e.g. P12DT12H15M
Edm.TimestringISO 8601 duration restricted to the day part, e.g. PT12H15M
Edm.DateTimestring/Date(<milliseconds>)/, e.g. /Date(1672485300000)/

As you can see:

  • All values are simple in the end: When in doubt it's a string!
    • easily serializable
    • not cool for end user to use in raw form
  • In V2 most number types are just strings, V4 makes that better
  • Date and Time types are a story of their own

V2 Data Types

The special thing about V2 OData services is, that we have to differentiate between using OData types in the URL or in JSON, since they are formatted differently:

  • URL: values in filter queries ($filter) or function parameters (which are query parameters)
  • JSON: values in request or response bodies

The following table lists information about all V2 data types according to the official resources used.

For URL usage, see chapter 6 "Primitive Data Types" of the V2 overview document. This is the most authoritative resource despite it's lack of being a true specification.

For JSON usage, see chapter 4 "Primitive Types" of the document about the V2 JSON format.

OData V2 TypeDescriptionURL formatURL exampleJSON typeJSON example
Edm.Booleanboolean valueliteraltruebooleantrue
Edm.Stringstring valuequoted'test'string"test"
Edm.Byteunsigned 8-bit integer valueliteral1string"1"
Edm.SBytesigned 8-bit integer valueliteral-1string"-1"
Edm.Int16signed 16-bit integer valueliteral123number123
Edm.Int32signed 32-bit integer valueliteral123number123
Edm.Int64signed 64-bit integer valuetype suffix "L"123Lstring"123"
Edm.Singlefloating point number with 7 digits precisiontype suffix "f"1.1fstring"1.1"
Edm.Doublefloating point number with 15 digits precisiontype suffix "d"1.2dstring"1.2"
Edm.Decimalnumeric values with arbitrary precision and scaletype suffix "M" or "m"12.22Mstring"12.22
Edm.Guid16-byte (128-bit) unique identifier valuetype prefix "guid"guid'xxx...'string"xxx..."
Edm.Timeday time duration representing time of daytype prefix "time"time'PT12H59M10S'string"PT12H59M10S"
Edm.DateTimespecific point in timetype prefix "datetime"datetime'2022-12-31T23:59:59'string"/Date(123...)/"
Edm.DateTimeOffsetspecific point in timetype prefix "datetimeoffset"datetimeoffset'2022-12-31T23:59:59Z'string"2022-12-31T23:59:59+01:00"
Edm.Binaryfixed or variable length binary datatype prefix "X" or "binary"binary'23A'base64 encoded string"..."

Oddities

Edm.DateTime is quite special in multiple ways:

  1. URL and JSON representation are completely different
  2. the JSON representation has quite a unique format
  3. Edm.DateTime is not really consistent with Edm.DateTimeOffset

Another oddity is Edm.Time, since it is defined as duration (by the way, the static "P" stands for "period"). Now the "spec" states, that it should represent a specific time of day and refers to the "day time duration" as definition.

I think that the definition is flawed for two reasons. First, "day time duration" also allows for specifying a period of days, which doesn't overlap with time of day. Second, a duration might be able to represent a time of day, in the sense that a duration of 6 hours and 12 minutes might also represent "06:12", but both data types usually have different restrictions. Time of day requires the specification of hours and minutes, while duration might specify any of its parts, e.g. only seconds "PT12S".

V4 Data Types

OData V4 TypeDescriptionURL formatURL ExampleJSON type
Edm.Booleanboolean valueliteraltrue
false
boolean
Edm.Stringstring valuequoted'Some Test'string
Edm.Byteunsigned 8-bit integer valueliteral1number
Edm.SBytesigned 8-bit integer valueliteral-1number
Edm.Int16signed 16-bit integer valueliteral123number
Edm.Int32signed 32-bit integer valueliteral123number
Edm.Int64signed 64-bit integer valueliteral123number
Edm.Singlefloating point number with 7 digits precisionliteral1.1number
Edm.Doublefloating point number with 15 digits precisionliteral1.2number
Edm.Decimalnumeric values with arbitrary precision and scaleliteral12.22number
Edm.Guid16-byte (128-bit) unique identifier valueliteral...string
Edm.DurationdurationliteralPT12H59M10S
P1Y
PT12.123S
string
Edm.TimeOfDayspecific time of dayliteral12:59:10
12:15
12:15:03.123
string
Edm.Datespecific dayliteral2022-12-31string
Edm.DateTimeOffsetspecific point in timeliteral2022-12-31T23:59:59Z
2022-12-31T23:59:59+02:00
string
Edm.Binaryfixed or variable length binary database64 encoded string
Edm.Streammost filter operations don't work here
also exclusive handling
Edm.Geography.*
Edm.Geometry.*

Conclusions

  • Sensible data types especially regarding date and time types
  • The one exception are big number types: Edm.Double and Edm.Decimal
    • V4 overreached there a bit, as Decimal and Double could lose precision unnoticed when converted to JS Number
    • you have to use a special header to turn these types into strings again