[
https://issues.apache.org/jira/browse/TINKERPOP3-581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14390397#comment-14390397
]
stephen mallette commented on TINKERPOP3-581:
---------------------------------------------
hmm - don't want to lose all those tests if i don't have to. this might be the
reason too why we didn't see this problem with Titan 0.9.
regarding your point about lossiness, i guess i would say that GraphSON isn't a
database system. Neither is GraphML which is even more lossy than GraphSON.
They are serialization formats - formats that the database maps to. embedTypes
creates really ugly JSON and is mostly useful for serialization within the JVM.
standard JSON is better in that it is more easily consumable and will be the
primary means that non-JVM languages map their types to.
Another idea just came to me given your comment on lossiness:
4. treat identifiers as a special case that always serialize/deserialize
properly over json.
I think i will explore this case before the others.
> GraphSONWriter and CustomId issue
> ---------------------------------
>
> Key: TINKERPOP3-581
> URL: https://issues.apache.org/jira/browse/TINKERPOP3-581
> Project: TinkerPop 3
> Issue Type: Bug
> Components: test-suite
> Reporter: pietermartin
> Priority: Critical
> Fix For: 3.0.0.GA
>
>
> Hi,
> I have had to change sqlg to use a custom id field but alas am struggling to
> get the graphson IoTests to pass.
> Sqlg's id now is in json
> {code}
> {"id": {"schema":"public", "table":"Person","id"123}}
> {code}
> I have overriden the folowing Graph.Io methods.
> {code}
> @Override
> public GraphSONMapper.Builder graphSONMapper() {
> final SimpleModule module = new SimpleModule();
> module.addSerializer(RecordId.class, new
> RecordId.RecordIdJacksonSerializer());
> module.addDeserializer(RecordId.class, new
> RecordId.CustomIdJacksonDeserializer());
> //return GraphSONMapper.build().addCustomModule(module);
> return
> GraphSONMapper.build().addCustomModule(module).embedTypes(true);
> }
> {code}
> and in RecordId
> {code}
> static class RecordIdJacksonSerializer extends StdSerializer<RecordId> {
> public RecordIdJacksonSerializer() {
> super(RecordId.class);
> }
> @Override
> public void serialize(final RecordId customId, final JsonGenerator
> jsonGenerator, final SerializerProvider serializerProvider)
> throws IOException {
> ser(customId, jsonGenerator, false);
> }
> @Override
> public void serializeWithType(final RecordId customId, final
> JsonGenerator jsonGenerator,
> final SerializerProvider
> serializerProvider, final TypeSerializer typeSerializer) throws IOException {
> ser(customId, jsonGenerator, true);
> }
> private void ser(final RecordId recordId, final JsonGenerator
> jsonGenerator, final boolean includeType) throws IOException {
> jsonGenerator.writeStartObject();
> if (includeType)
> jsonGenerator.writeStringField(GraphSONTokens.CLASS,
> RecordId.class.getName());
> SchemaTable schemaTable = recordId.getSchemaTable();
> jsonGenerator.writeObjectField("schema", schemaTable.getSchema());
> jsonGenerator.writeObjectField("table", schemaTable.getTable());
> jsonGenerator.writeObjectField("id", recordId.getId().toString());
> jsonGenerator.writeEndObject();
> }
> }
> static class CustomIdJacksonDeserializer extends
> StdDeserializer<RecordId> {
> public CustomIdJacksonDeserializer() {
> super(RecordId.class);
> }
> @Override
> public RecordId deserialize(final JsonParser jsonParser, final
> DeserializationContext deserializationContext) throws IOException,
> JsonProcessingException {
> String schema = null;
> String table = null;
> Long id = null;
> while (!jsonParser.getCurrentToken().isStructEnd()) {
> if (jsonParser.getText().equals("schema")) {
> jsonParser.nextToken();
> schema = jsonParser.getText();
> } else if (jsonParser.getText().equals("table")) {
> jsonParser.nextToken();
> table = jsonParser.getText();
> } else if (jsonParser.getText().equals("id")) {
> jsonParser.nextToken();
> id = Long.valueOf(jsonParser.getText());
> } else
> jsonParser.nextToken();
> }
> if (!Optional.ofNullable(schema).isPresent())
> throw deserializationContext.mappingException("Could not
> deserialze RecordId: 'schema' is required");
> if (!Optional.ofNullable(table).isPresent())
> throw deserializationContext.mappingException("Could not
> deserialze RecordId: 'table' is required");
> if (!Optional.ofNullable(id).isPresent())
> throw deserializationContext.mappingException("Could not
> deserialze RecordId: 'id' is required");
> return new RecordId(SchemaTable.of(schema, table), id);
> }
> }
> {code}
> When using {{.embedTypes(true)}} the serialization works but the lossy tests
> fail as Jackson then does not upgrade floats to doubles.
> If I omit the {{embedTypes(true)}} then the tests fail as the id is never
> deserialized to my custom RecordId.
> The test I am currently testing on is
> {{IoTest.shouldReadWriteVertexWithOUTOUTEdgesToGraphSON}}
> With {{embedTypes(true)}} ommited the test fails with
> {code}
> org.junit.ComparisonFailure:
> Expected :public.person:::1
> Actual :{schema=public, table=person, id=1}
> {code}
> With {{embedTypes(true)}} included the test fails with
> {code}
> java.lang.ClassCastException: java.lang.Float cannot be cast to
> java.lang.Double
> {code}
> Any ideas as to what to do?
> Thanks
> Pieter
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)