[JAVA-2173] add new Enum value for org.bson.json.JsonMode Created: 20/Apr/16 Updated: 09/Mar/17 Resolved: 09/Mar/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | sun mingxin | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
All |
||
| Issue Links: |
|
||||||||||||
| Description |
|
For below code
The output is
If we change code as
It generates
However in some circumstance, we expect to get the simple
In the implementation of JsonWriter.doWriteInt64(), there is a default switch case for such output, but it never goes there because JsonMode has only two exact enum value. So please add one new enum value for JsonMode, and then we can write code as
and then can get the simple output
|
| Comments |
| Comment by Jeffrey Yemin [ 09/Mar/17 ] | |||||||||||||||||||||||||||
|
In scope of
Given this added flexibility, we no longer plan to add a new output mode for this use case. | |||||||||||||||||||||||||||
| Comment by Aleksey Korolev [ 09/Jun/16 ] | |||||||||||||||||||||||||||
|
I stumbled upon the same problem after migrating my code from Java driver version 2.x to 3.x.
To my mind the code from default case branch must be moved to STRICT case branch. | |||||||||||||||||||||||||||
| Comment by sun mingxin [ 22/Apr/16 ] | |||||||||||||||||||||||||||
|
More seriously, it breaks the compatible. All existing client code are dealing { "a" : 12, "b" : 14 }when we are using legacy DBObject, but now the server returns a complex string and client code fails. | |||||||||||||||||||||||||||
| Comment by sun mingxin [ 21/Apr/16 ] | |||||||||||||||||||||||||||
|
So far we have no such issue. I go through the source again and find it will throw exception for object id and date type if the JsonMode is neither the two. So a better suggestion may be allowing customized writer to construct perferred output format. | |||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 20/Apr/16 ] | |||||||||||||||||||||||||||
|
Do you have any issues with the way other BSON types are represented as JSON? For instance, an ObjectId will look like this:
while a Date will look like this:
|