#Jackson optimize JSON readability

1 messages · Page 1 of 1 (latest)

glad wolf
#

For some background info, I'm working of a Library of interfaces/classes and algorithms related to Graph Theory.

I'd like to know if anyone has ideas on how to make the JSON produced by jackson of my graph interface to be more readable. The current setup has a map of node labels to adjacency lists as well as a List of nodes, containing their Type and properties (currently just a label for the default impl).

I've provided a reference of how one such json looks, what the graph its representing is and the Wrapper I'm using to configure my ObjectMapper.

If you have any suggestions on how I can make the produced json more readable, I'd love to hear them.

versed scaffoldBOT
#

<@&987246399047479336> please have a look, thanks.

stiff bough
glad wolf
# stiff bough Why do you have class names in the json ??? And you could convert the graph into...

Since Graphs can have different Types of nodes and edges inside, it's impossible to know the node type just off of the properties. Additionally, since the library interfaces and classes are designed to be extended, I need to support custom implementations so telling jackson what class to create for each element of the graph is neccessary (as far as I'm aware).

Although I don't know much about LaTeX from what I can gather it doesn't seem like it would very effectively store custom properties nodes and edges may have

stiff bough
glad wolf
#

I'm just wondering if there's a way to compress this, even a little

stiff bough
#

Also your json is bad because it contains implementations, even if you use class names, you should never use implementations

stiff bough
#

or black magic

glad wolf
stiff bough
#

that's the problem

#

you need to code this yourself

#

so try to code your program in a smarter way

glad wolf
stiff bough
#

Also note that allowing any class to be used means that you can't run it unless you have those classes, which could cause a lot of problems

glad wolf
#

that's perfectly fine

stiff bough
stiff bough
glad wolf
#

such as creating a user Node with information about users

#

or any other implementation they might need

glad wolf
#

because the information won't be useful without the classes anyways

stiff bough
glad wolf
stiff bough
#

And if someone wants some hyper specific stuff, then they might as well fork your lib

#

And remember that you can't code something that could be extended in any ways
There are always limits, and so you need to set them correctly and code with that in mind

#

You can't just say "I'll allow anything"

glad wolf
glad wolf
glad wolf
#

however that doesn't mean I should focus my efforts on creating every conceivable implementation imaginable

#

I should work to let users fit the library to their needs

stiff bough
glad wolf
#

that's true, I can probably remove that

#

that information is given when you read it in

stiff bough
#

First please define what could possibly be in the graph

glad wolf
stiff bough
#

if you manage to find everything, then none of the classes need to be displayed

glad wolf
stiff bough
glad wolf
glad wolf
stiff bough
#
  • Nodes
  • Edges
    That's kinda all
glad wolf
#

for a map software, the nodes would have the address, information about the location, and information to assist in finding routes such as average wait times for intersections.

Edges are much the same just representing roads, information such as road names, average time to pass, speed limits, safety, etc. as well as information to assist in finding routes

stiff bough
#

Edges may have information about their nodes, one or several labels + positions (start, end middle) + angle, id, stroke color, stroke width, direction or none, and then data
Nodes may have one or several labels + positions (center, outside from an angle) + angle, id, radius, stroke color, stroke width background color, and then data

stiff bough
glad wolf
#

You're right, they could simply contain a reference to another object

tawdry grove
#

something like this

#

and you pick a deserializer from "type"

stiff bough
#
class Node<N> {
  ...
  private N data
}
class Edge<E> {
  ...
  private E data
}
class Graph<N, E> {
  private List<Node<E>> edges;
  private List<Edge<N>> nodes;
  ...
}
#

then create your own data class

#

Like RoadData

tawdry grove
#

or use a Guava graph tbh

tawdry grove
#
<dependency>
    <groupId>dev.mccue</groupId>
    <artifactId>guava-graph</artifactId>
    <version>33.2.0</version>
</dependency>
stiff bough
#

so then you handle everything about graphes only

glad wolf
tawdry grove
#

oh okay

stiff bough
#

and then, the data is user specific, and you can easily transform it into json as long as the user create a method to jsonify it tho you will need classes in the json but only for data

#

and what if you want no data?

#

Just use Void type

#

You could even make a class for this

glad wolf
#

yeah that makes perfect sense

stiff bough
#
Graph<Void, Void> graph = new Graph<>();
// Or for easier use
class SimpleGraph extends Graph<Void, Void>(){}
SimpleGraph graph = new SimpleGraph();
glad wolf
#

yeah, that makes a lot more sense than what I was doing. Thanks a lot

#

also how do I close this question?

versed scaffoldBOT
#

Closed the thread.

glad wolf
#

ah there

stiff bough
glad wolf
#

💀

#

now I have to wait 2 minutes