Created
April 23, 2022 18:06
-
-
Save AnarCom/07ff7edf7099821d6fd726cb58e5088e to your computer and use it in GitHub Desktop.
Rete js + jackson deserialization example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.annotation.JsonSubTypes; | |
import com.fasterxml.jackson.annotation.JsonTypeInfo; | |
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | |
import com.fasterxml.jackson.annotation.JsonTypeName; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Map; | |
import lombok.Data; | |
import lombok.Getter; | |
import lombok.Setter; | |
public class AnotherTestMain { | |
public static void main(String[] args) throws IOException { | |
// var t = new Dog(); | |
// t.barkVolume = 10; | |
// | |
// var json = new ObjectMapper().writeValueAsString(t); | |
// System.out.println(json); | |
// | |
// Animal an = new ObjectMapper().readerFor(Animal.class) | |
// .readValue(json); | |
// System.out.println(an); | |
var reader = new BufferedReader(new FileReader("./test.json")); | |
StringBuilder b = new StringBuilder(); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
b.append(line); | |
} | |
String json = b.toString(); | |
NodeGroup a = new ObjectMapper().readValue(json, NodeGroup.class); | |
System.out.println("hg"); | |
} | |
@Data | |
public static class NodeGroup { | |
private String id; | |
Map<String, AbstractNode> nodes; | |
} | |
@JsonTypeInfo( | |
use = JsonTypeInfo.Id.NAME, | |
include = As.PROPERTY, | |
property = "name") | |
@JsonSubTypes({ | |
@JsonSubTypes.Type(value = AddNode.class, name = "Add") | |
// @JsonSubTypes.Type(value = Cat.class, name = "cat") | |
}) | |
@Getter | |
@Setter | |
public static abstract class AbstractNode { | |
Integer id; | |
// data | |
private Integer[] position; | |
private Map<String, InputConnection> inputs; | |
private Map<String, OutputConnection> outputs; | |
} | |
@Data | |
static class InputConnection { | |
private Main.InputConnectionData[] connections; | |
} | |
@Data | |
static class InputConnectionData { | |
private Integer node; | |
private String output; | |
private Map<String, Object> data; | |
} | |
@Data | |
static class OutputConnection { | |
private Main.OutputConnectionData[] connections; | |
} | |
@Data | |
static class OutputConnectionData { | |
private Integer node; | |
private String input; | |
private Map<String, Object> data; | |
} | |
@JsonTypeName("Add") | |
@Getter | |
@Setter | |
static class AddNode extends AbstractNode { | |
private AddNodeData data; | |
static class AddNodeData { | |
public Integer num1; | |
public Integer num2; | |
public String preview; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment