question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example for exporting to JSON for Edge Labels

See original GitHub issue

Sorry for reposting here after posting to the Google group. I am in a Scrum sprint and am stuck here.

I am trying to export a graph that has labelled edges. The label is of type EffectiveDatedRelationships

case class EffectiveDatedRelationship(hierarchyId: String, edgeType: EdgeType, intervals: IntervalCollection[PlainDate])

IntervalCollection is a class from time4j library. http://www.time4j.net/javadoc-en/

Essentially what I want is to get the list of intervals out of the IntervalCollection and store each pair of start date and end date as an array of tuples (2 element arrays or object) in JSON. For deserialization I will reach each array element and add it to the IntervalCollection object via its plus() method.

The LDi.descriptor method requires a parameter of type L, what should I put as the parameter? I tried to put null and it can run but the intervals element is not exported. I suspect it is because the JSON serialization does not know how to handle this class. How can I define the serialization/deserializaiton logic? I looked at the customSerializer parameter but could not figure out what to do.

Descriptor definition:

import scalax.collection.io.json.descriptor.predefined.LDi
val descriptor = new Descriptor[HierarchyNode](
  defaultNodeDescriptor = portfolioNodeDescriptor,
  defaultEdgeDescriptor = LDi.descriptor[HierarchyNode, EffectiveDatedRelationship](null),
  namedNodeDescriptors  = Seq(rootNodeDescriptor),
  namedEdgeDescriptors  = Seq(LDi.descriptor[HierarchyNode, EffectiveDatedRelationship](null))

def toJson(bundle: PortfolioHierarchyBundle) = {
  bundle.graph.toJson(descriptor)
}

Sample: JSON output: {"nodes":{"RootNodes":[{"id":"dummy"}],"PortfolioNodes":[{"portfolioId":"top1"},{"portfolioId":"parent"},{"portfolioId":"child"},{"portfolioId":"top2"}]},"edges":[{"n1":"dummy","n2":"top1","label":{"hierarchyId":"dummy","edgeType":{"i":0,"name":null},"intervals":{}}},{"n1":"dummy","n2":"top2","label":{"hierarchyId":"dummy","edgeType":{"i":0,"name":null},"intervals":{}}},{"n1":"parent","n2":"child","label":{"hierarchyId":"dummy","edgeType":{"i":0,"name":null},"intervals":{}}},{"n1":"top2","n2":"parent","label":{"hierarchyId":"dummy","edgeType":{"i":0,"name":null},"intervals":{}}},{"n1":"top1","n2":"parent","label":{"hierarchyId":"dummy","edgeType":{"i":0,"name":null},"intervals":{}}}]}

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peter-empencommented, Feb 8, 2018

I see. You can either a) swith from LDi.descriptor to LEdgeDescriptor or b) often better for other reasons such as type-safety of the lables, switch from LDiEdge to a custom edge. Then please refer to scalax.collection.io.json.TCustomEdge where Transition is a custom edge.

0reactions
peter-empencommented, Feb 9, 2018

Well done!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export parameter fields in the params top-level JSON object
The Neptune export params JSON object allows you to control the export, including the type and format of the exported data.
Read more >
3.2 Using JSON to Store Vertex and Edge Properties
The following two examples demonstrate how you can extract labels and property values from JSON objects for PGQL on RDBMS and PGQL on...
Read more >
JSON Format (ELK)
The JSON graph format has five basic elements: nodes, ports, labels, edges, and edge sections. Details about each element can be found below, ......
Read more >
Exporting and Importing Tags - Ignition User Manual 8.0
Below is an example of a JSON format Tag export. Descriptions on the various properties can be found on the Tag Properties and...
Read more >
JSON function in Power Apps - Power Platform
In this article. Description; Syntax; Examples. Generates a JSON text string for a table, a record, or a value.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found