arangodb / java-velocypack Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
When serializing an object having negative int value for one of its instance field, the returned serialized object have a weird value instead of the negative int value.
For example, if I call the following piece of code with an object having -50 as value for one of its int field, the serialized value for this field is 4294967246;
VPack vpack = vpack();
System.out.println(vpack.serialize(object).toString());
Hi,
the com.arangodb.velocypack.internal.util.DateUtil
does incorrect conversion of java.util.Date
objects. The error is that the format is set to ISO 8601 in UTC but the time zone is not taken into account.
A date, e.g. Mon Apr 16 17:17:21 CEST 2018
would be converted to 2018-04-16T17:17:21Z
, but correct would be 2018-04-16T15:17:21Z
.
Fix:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
Best regards
The VPackDeserializationContext
currently takes a Class<T>
as a parameter. The underlying code does not require a Class<T>
, it only requires the more general Type
.
By accepting a Type
in the VPackDeserializationContext.deserialize
interface method rather than Class<T>
, the user is free to pass in other implementations of Type
, such as ParameterizedType
which can be used to deserialize List
s with a parameterized type, as well as Map
s). These parameters can be generated and "reified" by using a "type token" implementation, such as is provided in Guava, and indeed in quite a few other libraries as well.
Along with some minor additional code in VPack.java
to deal with deserializing wildcard types e.g. if we try to deserialize into a list like List<? extends Foo>
this works quite well.
This does also require a minor change in a couple of places in the java driver to cast the result coming back from this call, because java's type inference sucks. I suppose for the same reason this is also a backward incompatible change, and so this probably requires a major version bump. However, I've left the versions alone for now.
When trying to parse json containing array with multiple objects with null values parser fails with exception.
String json = "{\"values\": [ {\"a\": null}, {\"b\": null}]}";
VPackParser parser = new VPackParser.Builder().build();
parser.fromJson(json);
Results in:
Unexpected exception at position -1: null
at com.arangodb.velocypack.VPackParser$VPackContentHandler.add(VPackParser.java:386)
at com.arangodb.velocypack.VPackParser$VPackContentHandler.startObject(VPackParser.java:444)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:488)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:301)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:295)
at com.arangodb.velocypack.VPackParser.fromJson(VPackParser.java:339)
at com.arangodb.velocypack.VPackParser.fromJson(VPackParser.java:331)
I'm using java-velocypack version 1.0.9
The deserialization should provide a way to deserialize polymorphic lists.
Presumably for this we have to store information about the concrete implementation in vpack (like jackson with JsonTypeInfo
).
It has add(final String attribute, final Byte value)
, so I would have expected a add(final Byte value)
to be present, like there are for all other data types. addTagged(final long tag, final Byte value)
is also missing.
With the latest update, the annotations @SerializezdName and @expose have been removed from this library and as far as I can tell, the functionality those provided no longer exists. Is there a migration process to move code that used those annotations to the latest version?
Version: 1.0.11
Test source code: https://gist.github.com/zqq90/2aa2e7aa6fdd7453e50d26cb0bc22b30
Exceptions like:
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to java.lang.Class
at com.arangodb.velocypack.VPack.addValue(VPack.java:854)
at com.arangodb.velocypack.VPack.serializeField(VPack.java:824)
...
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at com.arangodb.velocypack.VPack.addValue(VPack.java:854)
at com.arangodb.velocypack.VPack.serializeField(VPack.java:824)
...
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at com.arangodb.velocypack.VPack.getValue(VPack.java:560)
at com.arangodb.velocypack.VPack.deserializeCollection(VPack.java:597)
...
Consider the following (kotlin) code, using java-velocypack 2.2.1:
val slice = with(VPackBuilder(object : VPackBuilder.BuilderOptions {
override fun isBuildUnindexedArrays() = true
override fun isBuildUnindexedObjects() = true
override fun setBuildUnindexedArrays(buildUnindexedArrays : Boolean) = throw NotImplementedError()
override fun setBuildUnindexedObjects(buildUnindexedObjects : Boolean) = throw NotImplementedError()
}))
{
add(ValueType.ARRAY)
add(1)
close()
slice()
}
println(slice)
println(slice.toByteArray().toList())
Expected output would be (note that the byte values are base 10):
[1]
[19, 4, 49, 1]
Actual output is:
["(non-representable type)"]
[19, 4, 0, 1]
The output is as expected (albeit with a larger byte array) when isBuildUnindexedArrays() = false
. The output is also as expected when not using small integer values.
The VPackBuilder seems to write the 1 correctly as 49 into its buffer, but fails to copy it to the correct position in VPackBuilder::closeCompactArrayOrObject
.
Excuse the code (working with Clojure)
As a slice can contain a single element.
(-> (new VPackBuilder)
(.add ValueType/OBJECT)
(.add "foo" "bar")
.close
.slice
(.get "foo"))
#object[com.arangodb.velocypack.VPackSlice 0x2b9072bd "\"bar\""]
Is there a canonical way of creating a single element slice?
(-> (new VPackBuilder)
(.add ValueType/ARRAY)
(.add "bar")
.close
.slice
(.get 0))
#object[com.arangodb.velocypack.VPackSlice 0x1eb0779a "\"bar\""]
Arangodb content like {\n \"description\": \"String with new line\"\n} was ok for version 2.5.2.
Version 2.5.3 requires {\\n \"description\": \"String with new line\"\\n} otherwise Jackson ObjectMapper throws Exception with json String from VPackParser.toJson.
Is this change intentional or a bug?
See example v2.5.3 vs example v2.5.2
The VPackBuilder used while parsing the Json string is always created with the default options, so it is impossible to get a VPackSlice with unindexed arrays/objects.
Hi!
I saw that BigInteger
is serialized as long
and BigDecimal
as double
. But they can easily overflow long
and double
(that's why they exist ;)). Wouldn't it be better to serialize both as String
?
Greetings,
Christian
Hi, can the json implementation be switched to Jackson? Jackson is standardized and used across the board in most projects. json-simple creates an extra dependency for us. Also as it's more heavily tested any issues, such as security are better looked after.
As an added bonus Jackon is faster. If size is an issue please look at jackson-jr.
Thanks!
When serializing an array of an abstract class or interface, a type hint should be added to the items, just like it's done for generic lists.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.