BSON codecs JSR-310

BSON codecs for Java 8 Date and Time API (JSR-310).

License

License

GroupId

GroupId

io.github.cbartosiak
ArtifactId

ArtifactId

bson-codecs-jsr310
Last Version

Last Version

3.5.4
Release Date

Release Date

Type

Type

jar
Description

Description

BSON codecs JSR-310
BSON codecs for Java 8 Date and Time API (JSR-310).
Project URL

Project URL

https://github.com/cbartosiak/bson-codecs-jsr310
Source Code Management

Source Code Management

https://github.com/cbartosiak/bson-codecs-jsr310

Download bson-codecs-jsr310

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.cbartosiak/bson-codecs-jsr310/ -->
<dependency>
    <groupId>io.github.cbartosiak</groupId>
    <artifactId>bson-codecs-jsr310</artifactId>
    <version>3.5.4</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.cbartosiak/bson-codecs-jsr310/
implementation 'io.github.cbartosiak:bson-codecs-jsr310:3.5.4'
// https://jarcasting.com/artifacts/io.github.cbartosiak/bson-codecs-jsr310/
implementation ("io.github.cbartosiak:bson-codecs-jsr310:3.5.4")
'io.github.cbartosiak:bson-codecs-jsr310:jar:3.5.4'
<dependency org="io.github.cbartosiak" name="bson-codecs-jsr310" rev="3.5.4">
  <artifact name="bson-codecs-jsr310" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.cbartosiak', module='bson-codecs-jsr310', version='3.5.4')
)
libraryDependencies += "io.github.cbartosiak" % "bson-codecs-jsr310" % "3.5.4"
[io.github.cbartosiak/bson-codecs-jsr310 "3.5.4"]

Dependencies

compile (1)

Group / Artifact Type Version
org.mongodb : bson jar 3.11.0

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.5.1
org.junit.jupiter : junit-jupiter-engine jar 5.5.1

Project Modules

There are no modules declared in this project.

BSON codecs for Java 8 Date and Time API (JSR-310)

Build Status Maven Central Javadocs

The library provides codecs for the following JSR-310 classes:

  • java.time.DayOfWeek
  • java.time.Duration
  • java.time.Instant
  • java.time.LocalDate
  • java.time.LocalDateTime
  • java.time.LocalTime
  • java.time.Month
  • java.time.MonthDay
  • java.time.OffsetDateTime
  • java.time.OffsetTime
  • java.time.Period
  • java.time.Year
  • java.time.YearMonth
  • java.time.ZonedDateTime
  • java.time.ZoneId
  • java.time.ZoneOffset

Usage

In order to utilize the codecs one can use CodecRegistries helper, for example in case of Mongo synchronous client:

MongoClient mongoClient = MongoClients.create();
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
        MongoClientSettings.getDefaultCodecRegistry(),
        CodecRegistries.fromCodecs(new DurationAsDecimal128Codec())
);
MongoDatabase database = client
        .getDatabase(...)
        .withCodecRegistry(codecRegistry);

Note that depending on a context a different set of codecs might be necessary. There are three main factors to consider when choosing codecs:

  • queryability - how much stored values are capable of being searched;
  • sortability - how much stored values are capable of being ordered;
  • readability - how much stored values are readable for human.

The table below presents the recommendations for all the factors. The more + signs a cell contains the better a row codec is in terms of a column factor:

Codec Queryability Sortability Readability
DayOfWeekAsInt32Codec ++ ++ +
DayOfWeekAsStringCodec + ++
DurationAsDecimal128Codec + ++
DurationAsDocumentCodec ++ + +
DurationAsStringCodec ++
InstantAsDateTimeCodec + ++ +
InstantAsDocumentCodec ++ + +
InstantAsStringCodec ++
LocalDateAsDateTimeCodec + ++ +
LocalDateAsDocumentCodec ++ + +
LocalDateAsStringCodec ++
LocalDateTimeAsDateTimeCodec + ++ +
LocalDateTimeAsDocumentCodec ++ + +
LocalDateTimeAsStringCodec ++
LocalTimeAsDateTimeCodec + ++ +
LocalTimeAsDocumentCodec ++ + +
LocalTimeAsInt64Codec ++ ++
LocalTimeAsStringCodec ++
MonthAsInt32Codec ++ ++ +
MonthAsStringCodec + ++
MonthDayAsDecimal128Codec + ++ ++
MonthDayAsDocumentCodec ++ + +
MonthDayAsStringCodec ++
OffsetDateTimeAsDocumentCodec ++ + +
OffsetDateTimeAsStringCodec ++
OffsetTimeAsDocumentCodec ++ + +
OffsetTimeAsStringCodec ++
PeriodAsDocumentCodec + +
PeriodAsStringCodec ++
YearAsInt32Codec ++ ++ ++
YearMonthAsDecimal128Codec + ++ ++
YearMonthAsDocumentCodec ++ + +
YearMonthAsStringCodec ++
ZonedDateTimeAsDocumentCodec ++ + +
ZonedDateTimeAsStringCodec ++
ZoneIdAsStringCodec + ++
ZoneOffsetAsInt32Codec ++ ++
ZoneOffsetAsStringCodec + ++

Versions

Version
3.5.4
3.4.0
3.3.0
3.2.0
3.1.3
3.1.2
3.1.1
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.1
2.0.0
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.2
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0