Hi ivyteam

Here i have an example about record on Ivy database (it's JSON) alt text

the @id is generated id of persistence but what is the meaning behind of its value? ex: $Ref-0, $Ref-1,... Thanks

asked 02.11.2016 at 08:53

trungdv's gravatar image

trungdv
(suspended)
accept rate: 52%


Every complex object that occurs in BusinessData will get a generated ID which has a prefix of "$Ref-" followed by an increasing integer.

This generated ID is used to store references to other objects in the same BusinessData without duplicating the JSON tree. It guarantees that stored objects will not only be equal after de-serialization, but also of same instance (if they we're at serialization time).

If an object is referenced multiple times within your BusinessData object tree, the first occurence of the object will be stored fully with an @id field. Any later reference will be stored with a simple back reference by using the "$Ref-X".

The following example demonstrates that. My java object tree is a class with has a CEO and CTO field. And these objects are also reference in an List within the "members" field.

Java Object Tree:

Persons persons = new Persons();
persons.members = new ArrayList<>();

V1 rew = new Persons.V1();
rew.firstName = "Reguel";
rew.lastName = "Wermelinger";
persons.members.add(rew);

V1 pes = new Persons.V1();
pes.firstName = "Peter";
pes.lastName = "Stöckli";
persons.members.add(pes);

persons.ceo = rew;
persons.cto = pes;

Serialized JSON:

{
  "@id" : "$Ref-0",
  "ceo" : {
    "@id" : "$Ref-1",
    "firstName" : "Reguel",
    "lastName" : "Wermelinger",
    "street" : null,
    "zip" : null,
    "city" : null
  },
  "cto" : {
    "@id" : "$Ref-2",
    "firstName" : "Peter",
    "lastName" : "Stöckli",
    "street" : null,
    "zip" : null,
    "city" : null
  },
  "members" : [ "$Ref-1", "$Ref-2" ]
}
link

answered 02.11.2016 at 12:01

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

edited 02.11.2016 at 12:03

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×35
×32

Asked: 02.11.2016 at 08:53

Seen: 3,673 times

Last updated: 02.11.2016 at 12:03