I'm trying to store a field of type java.time.ZoneId
in MongoDB. For this type, I require an org.bson.codecs.Codec
which I do have. However, when I try to insert the ZoneId
it gives the following:
Can't find a codec for class java.time.ZoneRegion
This is where this block of code comes in:
package java.time
static ZoneId of(String zoneId, boolean checkAvailable) {
Objects.requireNonNull(zoneId, "zoneId");
if (zoneId.length() <= 1 || zoneId.startsWith("+") || zoneId.startsWith("-")) {
return ZoneOffset.of(zoneId);
} else if (zoneId.startsWith("UTC") || zoneId.startsWith("GMT")) {
return ofWithPrefix(zoneId, 3, checkAvailable);
} else if (zoneId.startsWith("UT")) {
return ofWithPrefix(zoneId, 2, checkAvailable);
}
return ZoneRegion.ofId(zoneId, checkAvailable);
}
It is creating a ZoneRegion
for my case ZoneId.of("Africa/Harare")
.
ZoneRegion
is private which is causing problems for me as I now can't create a codec for it:
final class ZoneRegion extends ZoneId implements Serializable
println(ZoneId.of("Africa/Harare").getClass)
class java.time.ZoneRegion
The question is. How do I implement a codec for ZoneRegion
?
Any help would be greatly appreciated.