#Transform complex java object to and from JSON
3 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @valid ether! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
I've tried gson and jackson. it throws infinite loop error, I suspect because the class is too complex. What is a good way to create 2 methods to create JSON and obtain the netwokdesign class from json?
public abstract class NetworkDesign implements Serializable {
public enum Category {
SES("SES"),
EQPT("EQPT"),
OPTICAL(null),
IP("IP"),
NODE("NODE");
public enum Type {
EQPT(Category.EQPT),
Category category;
private Type(Category category) {
this.category = category;
}
}
private static final long serialVersionUID = 1L;
protected final String id;
protected String parentId;
protected Set<String> aliases;
protected final Set<NetworkLink> topLinks;
private final Set<NetworkLink> view;
private final Type type;
protected final Critique critique;
protected EnumSet<Purpose> applicablePurpose;
protected final Map<String, List<String>> userFlowMap;
protected String topologyOrigin;
private Date loadTime;
String server;
public NetworkDesign(String id, Type type) {
this.id = id;
this.parentId = null;
this.type = type;
aliases = new LinkedHashSet<String>();
aliases.add(id);
this.critique = new NetworkCritique();
applicablePurpose = EnumSet.of(Purpose.CUSTOMIZE);
this.topLinks = new LinkedHashSet<NetworkLink>();
this.parsedLinks = new LinkedHashSet<NetworkLink>();
view = Collections.unmodifiableSet(topLinks);
this.userFlowMap = CollectionUtil.createMultiMap();
this.loadTime = new Date();
try {
this.server = NetworkUtil.getInetAddressHostname();//InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
server = "unknown";
}
}