Skip to content

Commit

Permalink
Documentation added and corrected.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalFoksa committed Jun 15, 2021
1 parent 8f52e52 commit ba76375
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions avro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ byte[] avroData = mapper.writer(schema)

and that's about it, for now.

## Java Time Support
Serialization and deserialization support for limited set of `java.time` classes to Avro with [logical type](http://avro.apache.org/docs/current/spec.html#Logical+Types) is provided by `AvroJavaTimeModule`.

```java
AvroMapper mapper = AvroMapper.builder()
.addModules(new AvroJavaTimeModule())
.build();
```

#### Note
Please note that time zone information is at serialization. Serialized values represent point in time,
independent of a particular time zone or calendar. Upon reading a value back time instant is reconstructed but not the original time zone.

#### Supported java.time types:

Supported java.time types with Avro schema.

| Type | Avro schema
| ------------------------------ | -------------
| `java.time.OffsetDateTime` | `{"type": "long", "logicalType": "timestamp-millis"}`
| `java.time.ZonedDateTime` | `{"type": "long", "logicalType": "timestamp-millis"}`
| `java.time.Instant` | `{"type": "long", "logicalType": "timestamp-millis"}`
| `java.time.LocalDate` | `{"type": "int", "logicalType": "date"}`
| `java.time.LocalTime` | `{"type": "int", "logicalType": "time-millis"}`
| `java.time.LocalDateTime` | `{"type": "long", "logicalType": "local-timestamp-millis"}`

#### Precision

Avro supports milliseconds and microseconds previsions for date and time related logicalType(s). Only the milliseconds precision is supported.

## Generating Avro Schema from POJO definition

Ok but wait -- you do not have to START with an Avro Schema. This module can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* reconstruct the instant, but not the original representation.
*
* Note: In combination with {@link com.fasterxml.jackson.dataformat.avro.schema.DateTimeVisitor} it aims to produce
* Avro schema with type long with logicalType timestamp-millis:
* Avro schema with type long and logicalType timestamp-millis:
* {
* "type" : "long",
* "logicalType" : "timestamp-millis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* to a particular time zone or time of day.
*
* Note: In combination with {@link com.fasterxml.jackson.dataformat.avro.schema.DateTimeVisitor} it aims to produce
* Avro schema with type int with logicalType date:
* Avro schema with type int and logicalType date:
* {
* "type" : "int",
* "logicalType" : "date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* is considered local, with a precision of one millisecond from 1 January 1970 00:00:00.000.
*
* Note: In combination with {@link com.fasterxml.jackson.dataformat.avro.schema.DateTimeVisitor} it aims to produce
* Avro schema with type long with logicalType local-timestamp-millis:
* Avro schema with type long and logicalType local-timestamp-millis:
* {
* "type" : "long",
* "logicalType" : "local-timestamp-millis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* time zone or date, where the int stores the number of milliseconds after midnight, 00:00:00.000.
*
* Note: In combination with {@link com.fasterxml.jackson.dataformat.avro.schema.DateTimeVisitor} it aims to produce
* Avro schema with type int with logicalType time-millis:
* Avro schema with type int and logicalType time-millis:
* {
* "type" : "int",
* "logicalType" : "time-millis"
Expand Down

0 comments on commit ba76375

Please sign in to comment.