I posted the question cause I tested/read the docs/review the SDK code without finding a satisfying solution.
Using JsonObject.from(Map) will simply NOT work for the same reason you posted.
You can see that here:
Also, storing as a String is not an option. In my case I have an entity with a Map<String, Object> that can hold “big numbers” inside, and if I convert to String I lose the type information and I cannot convert back to the correct type.
Finally, Couchbase can store “big numbers” right, just because it stores a JSON and JSON Spec does not impose any constraints on range or precision for numbers, so this is a limitation only in the Java Client SDK.
I checked the Node SDK and the Go SDK and they don’t have that limitation.
On the other hand, using Jackson, you can map a BigInteger type without any problem.
Consider the following example:
damn, i like this kinda “Ey, lulke” challenges!
ok, first of all seems like you’ve dived down to JsonObject.fromJson => CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER.stringToJsonObject(s) => JacksonTransformers.MAPPER.readValue(input, JsonObject.class) )
As i understand from static initialization part, for “real parsing” following one method is used:
So, what about incoming numbers ? JsonParser.getValueAsNumber(), that returns java.lang.Number.
And what do we have ? No method (even abstract) for Number-> BigIntgeger conversation (https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html). Of course, there is always a BigInteger(String, radix), but radix can vary from 2 to 36, so how could we guess what radix this partucular BigInteger is? Are there any reasonable method to clarify, for example, what is the radix [2…36] for BigInteger that is the sequence of 1024 “1”-es (ie “111111 … 11111”) ? But formally it’s a Number.
About your example: i suppose that default implementation of om.readValue(json, Map.class) uses implicit consideration that incoming numbers > Long.MAX_VALUE are BigIntegers with radix = 10.
“What about all this, Luke” ?
P.S. +more, for example, 100% valid BigInteger “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa” (possible radix = [11…36]) is not even a Number.
Per my understanding the cb-java-client has Jackson as dependency and is using it to parse and serialize values, so why limit the types we can parse and serialize if Jackson supports a broader range of types.
I think the only change we need here is to add the Number class as valid type (or BigInteger or BigDecimal) in the checkType() method of the JsonValue class.
well, most likely, i was wrong and it could be done even easier than i thought.
Within your modification tests did you use (BigInteger)JsonObject’s get(“name”) method to fetch and put(“name”, bi) to set ?
It’s even funny: toString() for BigInteger returns 10-based (absolutely inefficient from the storing size viewpoint) string representation (but formally it’s a Number) and seems like this allows such an easy way to use it
Probably, you should also add a method getBigInteger(), so looks like https://github.com/couchbase/couchbase-java-client/blob/master/CONTRIBUTING.md awaits you
P.S. In other hand, i think, these should be told:
10-radix is an inefficient way to store big integers (especially when we are talking not about “12345678901234567890” but about hundreds/thousands-chars in string-form-representation for cases like DH/SRP-like authentication procedures)
no radix except 10 for BigIntegers could be used with other API/REST calls for database if you use JavaSDK with this improvement
documentation should also explicitly say that “we store big integers in form of string with radix 10”
But all these is more like “lyrics”, so why don’t you just try ?