-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-18711: Explain BsonRepresentation limitation #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package fundamentals; | ||
|
||
import org.bson.BsonReader; | ||
import org.bson.BsonWriter; | ||
import org.bson.codecs.Codec; | ||
import org.bson.codecs.DecoderContext; | ||
import org.bson.codecs.EncoderContext; | ||
|
||
// start class | ||
public class LongCodec implements Codec<Long> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would convert all Longs to a Date times, which wouldn't be desired by users.
Requires a Codec that implements
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thanks for providing this code! |
||
|
||
@Override | ||
public void encode(BsonWriter writer, Long value, EncoderContext encoderContext) { | ||
if (value != null) { | ||
writer.writeDateTime(value); | ||
} | ||
} | ||
|
||
@Override | ||
public Long decode(BsonReader reader, DecoderContext decoderContext) { | ||
return reader.readDateTime(); | ||
} | ||
|
||
@Override | ||
public Class<Long> getEncoderClass() { | ||
return Long.class; | ||
} | ||
} | ||
// end class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to tech reviewer: I'm a little uncertain about this example code. The example provided in the ticket didn't convert between Long and Datetime, so I wrote my own example. Let me know if this needs to be updated!