JValue supports 32 bit integer with bson_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > JValue supports 32 bit integer with bson

JValue supports 32 bit integer with bson

 2012/6/18 15:13:57  mathgl  程序员俱乐部  我要评论(0)
  • 摘要:Json.netsupportsBsonhoweverJValueconverteveryintegervaluetoint64bit..Inbson.int32need4bytesandint64need8bytes...sothereisaroomtoimproveit.findJValue.csaddanewconstructorpublicJValue(intvalue):this(value,JTokenType.Integer){
  • 标签:

Json.net supports Bson however JValue convert every integer value to int64 bit..

?

In bson. int32 need 4 bytes and int64 need 8 bytes...so there is a room to improve it.

?

find JValue.cs

?

?

add a new constructor

?

public JValue(int value)
??????? : this(value, JTokenType.Integer)
??? { }

?

?

?

and then find

?

?

public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)

?

add some codes here:

?

case JTokenType.Integer:

+?? if (this._value is int)
+????????????? {
+????????????????? writer.WriteValue(Convert.ToInt32(this._value, CultureInfo. InvariantCulture));
+????????????? }
+????????????? else
+????????????? {
+????????????????? writer.WriteValue(Convert.ToInt64(_value, CultureInfo.InvariantCulture));
+????????????? }

?

?

build it..it should work fine with bson from now on.

?

  • 相关文章
发表评论
用户名: 匿名