I think - "think" being the key word - that Jackson parses that CLASS to
determine the deserializer to use and then hands your deserializer the
contents of the rest of the JSON (which is all the deserializers needs once
the right one is chosen).

On Mon, Jun 25, 2018 at 8:08 AM pieter gmail <pieter.mar...@gmail.com>
wrote:

> Hi,
>
> Just manage to get it to work, but not really sure whats going on.
>
> So Sqlg's RecordId itself consist of a SchemaTable and a Long. Both
> RecordId and SchemaTable has serialization code.
>
> The part I don't quite get is that serializeWithType and deserialize is
> not symmetrical.
> Here is RecordId's serialization code.
>
>          @Override
>          public void serializeWithType(final RecordId recordId, final
> JsonGenerator jsonGenerator,
>                                        final SerializerProvider
> serializerProvider, final TypeSerializer typeSerializer) throws
> IOException, JsonProcessingException {
>
>              jsonGenerator.writeStartObject();
> jsonGenerator.writeStringField(GraphSONTokens.CLASS,
> RecordId.class.getName());
>              jsonGenerator.writeObjectField("schemaTable",
> recordId.getSchemaTable());
>              jsonGenerator.writeNumberField("id", recordId.getId());
>              jsonGenerator.writeEndObject();
>          }
>
>          @Override
>          public RecordId deserialize(final JsonParser jsonParser, final
> DeserializationContext deserializationContext) throws IOException,
> JsonProcessingException {
>              org.apache.tinkerpop.shaded.jackson.core.JsonToken
> jsonToken = jsonParser.nextToken();
>              Preconditions.checkState(JsonToken.START_OBJECT == jsonToken);
>              SchemaTable schemaTable =
> deserializationContext.readValue(jsonParser, SchemaTable.class);
>              jsonToken = jsonParser.nextToken();
> Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.FIELD_NAME
>
> == jsonToken);
> Preconditions.checkState("id".equals(jsonParser.getValueAsString()));
>              jsonToken = jsonParser.nextToken();
>              Preconditions.checkState(JsonToken.VALUE_NUMBER_INT ==
> jsonToken);
>              long id = jsonParser.getValueAsLong();
>              jsonToken = jsonParser.nextToken();
> Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.END_OBJECT
>
> == jsonToken);
>              return RecordId.from(schemaTable, id);
>          }
>
> What happened to the GraphSONTokens.CLASS ?
> I was expecting to have to read that also but somewhere I have lost the
> flow.
>
> Just to reiterate it is working now and all the tests are passing, so
> its more of a information question.
>
> Thanks
> Pieter
>
>
> On 25/06/2018 13:38, Stephen Mallette wrote:
> > I would think that you could write your own custom deserializer if you
> > needed to. That error doesn't give me any hints as to what might be wrong
> > exactly. I can't think of why that wouldn't work, but even with a little
> > refresh by looking at the code just now, my memory on GraphSON 1.0 is
> fuzzy.
> >
> > Maybe you could try to modify the working test in TinkerPop to include a
> > deserializer and see if you get a similar error for your efforts? Perhaps
> > that would help yield a clue?
> >
> > On Mon, Jun 25, 2018 at 2:58 AM pieter gmail <pieter.mar...@gmail.com>
> > wrote:
> >
> >> Hi,
> >>
> >> I am trying to upgrade Sqlg to 3.3.3 from 3.3.1.
> >>
> >> The only tests that are failing are the io tests for graphson V1.
> >>
> >> I see CustomId has a CustomIdJacksonSerializerV1d0 but not a
> >> deserializer. Looks like Jackson is using reflection to instantiate the
> >> CustomId and set its cluster and elementId.
> >> Is this how it must be or can it work with a deserializer? Sqlg's
> >> RecordId does not have default constructors.
> >>
> >> For Sqlg I added the standard deserializer but it fails with.
> >>
> >> org.apache.tinkerpop.shaded.jackson.databind.exc.InvalidTypeIdException:
> >> Could not resolve type id 'org.umlg.sqlg.structure.SchemaTable' as a
> >> subtype of [map type; class java.util.LinkedHashMap, [simple type, class
> >> java.lang.Object] -> [simple type, class java.lang.Object]]: Not a
> subtype
> >>    at [Source: (ByteArrayInputStream); line: 1, column: 105] (through
> >> reference chain: java.util.HashMap["id"])
> >>
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext.invalidTypeIdException(DeserializationContext.java:1628)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.DatabindContext.resolveSubType(DatabindContext.java:200)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.jsontype.impl.ClassNameIdResolver._typeFromId(ClassNameIdResolver.java:49)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.jsontype.impl.ClassNameIdResolver.typeFromId(ClassNameIdResolver.java:44)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:156)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.deser.std.MapDeserializer.deserializeWithType(MapDeserializer.java:400)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext.readValue(DeserializationContext.java:759)
> >>       at
> >>
> >>
> org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext.readValue(DeserializationContext.java:746)
> >>       at
> >>
> >>
> org.umlg.sqlg.structure.RecordId$RecordIdJacksonDeserializerV1d0.deserialize(RecordId.java:205)
> >>
> >> Any ideas as to how I should implement this?
> >>
> >> Thanks
> >> Pieter
> >>
> >>
> >>
> >>
>
>

Reply via email to