[JAVA-441] In BasicBSONCallback treat a Symbol as such Created: 03/Oct/11  Updated: 04/Nov/16  Resolved: 04/Nov/16

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 2.6.5
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Guy Boertje Assignee: Unassigned
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JVM languages


Backwards Compatibility: Major Change

 Description   

The Ruby driver can save and retrieve a BSON Symbol if the saved document is modified via JVM langauges that wrap the Java driver, the Symbol would be replaced with a String.

To allow retrieving of Bson Symbols I would suggest this:

_put( name , new Symbol(v) );

I have patched and jar'ed my fork and my tests in JRuby do save and retrieve a Ruby Symbol.

I am not in a position to check the other JVM languages though, sorry.



 Comments   
Comment by Jeffrey Yemin [ 04/Nov/16 ]

It's far too late now to change this, as it would break existing users expectations, but note that the Document class introduced in the 3.0 driver preserves the Symbol type. See https://github.com/mongodb/mongo-java-driver/blob/8799770704adfcfea47ff6703db2ec6d9a42be9f/bson/src/test/unit/org/bson/codecs/DocumentCodecSpecification.groovy#L79-L79

Comment by Graham Thomson [ 05/Feb/14 ]

+1 from me - this is essential for lossless reporting of type.

Note that patching that line to

public void gotSymbol( String name , String v )

{ _put( name , new Symbol( v ) ); }

is not enough, you also need to add an entry for it in com.mongodb.util.JSONSerializers.addCommonSerializers, e.g.

serializer.addObjectSerializer(Symbol.class, new ToStringSerializer());

Cheers,

Graham.

Generated at Thu Feb 08 08:52:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.