VPack Stack Overflow

37 views
Skip to first unread message

JPatrick Davenport

unread,
Mar 29, 2017, 12:03:33 AM3/29/17
to ArangoDB
Hello,
I have an object that points to itself. This appears to cause the serialize to wig out (infinitely recurse). Is there some flag to prevent this that I over looked?

Thanks,
JPD

mpv1989

unread,
Mar 29, 2017, 3:44:04 AM3/29/17
to ArangoDB
Hello,
you can use the annotation `Expose` on that field and set `serialize` and `deserialize` to `false` to ignore the field for serialization.
You can find an example in the docs.

Best,
Mark

JPatrick Davenport

unread,
Mar 31, 2017, 12:43:16 PM3/31/17
to ArangoDB
I need the field to point to itself. Java serialization gets around this issue by identifying the object in question. When it sees that object again, it knows to not serialize it, but use the instance it already has. I'm not sure how this could translate into a JSON based format.

mpv1989

unread,
Apr 12, 2017, 8:14:51 AM4/12/17
to ArangoDB
I see no generic and clean way to handle this with json. I would recommend the workaround with a custom `VPackDeserializer` for the self pointing class. This doesn't need any additional information stored in the document.

  public static class SelfPointingTestEntity {
   
private String foo;
   
private SelfPointingTestEntity self;


   
public SelfPointingTestEntity() {
     
super();
   
}
 
}


 
final ArangoDB.Builder builder = new ArangoDB.Builder().registerDeserializer(SelfPointingTestEntity.class,
   
new VPackDeserializer<SelfPointingTestEntity>() {
     
@Override
     
public SelfPointingTestEntity deserialize(
       
final VPackSlice parent,
       
final VPackSlice vpack,
       
final VPackDeserializationContext context) throws VPackException {
       
final SelfPointingTestEntity entity = new SelfPointingTestEntity();
        entity
.foo = vpack.get("foo").getAsString();
        entity
.self = entity;
       
return entity;
     
}
   
});
Reply all
Reply to author
Forward
0 new messages