/jedi-nodes-java

Generic node containers serializable/deserializable with jackson and other libraries.

Primary LanguageJavaApache License 2.0Apache-2.0

Versions

jedi-nodes-java

Utilities to serialize/deserialize to/from data formats: yaml, json, gson, xml, properties, csv, hocon, transposed json, etc

Features

Dataformat to POJO Mappers

TODO

Usage

Code

See test

class NodesTest {
  private static class SampleAddress {
    public String country = "Romania";
    public String city = "Bucharest";
  }

  private static class SamplePerson {
    public String name = "Taleb";
    public int age = 18;
    public OffsetDateTime birthdate = OffsetDateTime.of(1990, 1, 2, 3, 4, 5, 6, ZoneOffset.UTC);
    public SampleAddress address = new SampleAddress();
  }

  @Test
  void testAll() {
    SamplePerson a = new SamplePerson();
    System.out.println("CSV\n"+Nodes.csv.excluding("address").toString(a));
    System.out.println("CSV with YML\n"+Nodes.csv.toString(a));
    System.out.println("GSON\n"+Nodes.gson.toString(a));
    System.out.println("JSON\n"+Nodes.json.toString(a));
    System.out.println("PROP\n"+Nodes.prop.toString(a));
    System.out.println("XML\n"+Nodes.xml.toString(a));
    System.out.println("YML\n"+Nodes.yml.toString(a));
  }
  @Test
  void testDeserialization() {
    SamplePerson p1 = new SamplePerson();
    var content = Nodes.json.toString(p1);
    System.out.println(content);
    var p2 = Nodes.json.toObject(content, SamplePerson.class);
    System.out.println(p2);
  }
  ...
}

This will print

CSV
address,age,birthdate,name
,18,"1990-01-02T03:04:05.000000006Z",Taleb

CSV with YML
address,age,birthdate,name
"---
country: ""Romania""
city: ""Bucharest""
",18,"1990-01-02T03:04:05.000000006Z",Taleb

GSON
{
  "name": "Taleb",
  "age": 18,
  "birthdate": "1990-01-02T03:04:05.000000006Z",
  "address": {
    "country": "Romania",
    "city": "Bucharest"
  }
}
JSON
{
  "name" : "Taleb",
  "age" : 18,
  "birthdate" : "1990-01-02T03:04:05.000000006Z",
  "address" : {
    "country" : "Romania",
    "city" : "Bucharest"
  }
}
PROP
name=Taleb
age=18
birthdate=1990-01-02T03:04:05.000000006Z
address.country=Romania
address.city=Bucharest

XML
<SamplePerson>
  <name>Taleb</name>
  <age>18</age>
  <birthdate>1990-01-02T03:04:05.000000006Z</birthdate>
  <address>
    <country>Romania</country>
    <city>Bucharest</city>
  </address>
</SamplePerson>

YML
---
name: "Taleb"
age: 18
birthdate: "1990-01-02T03:04:05.000000006Z"
address:
  country: "Romania"
  city: "Bucharest"

Maven

Include this pom as parent.

<dependency>
  <groupId>org.raisercostin</groupId>
  <artifactId>jedi-nodes-java</artifactId>
  <version>0.4-SNAPSHOT</version>
</dependency>

Browse https://github.com/raisercostin/maven-repo/tree/master/org/raisercostin/jedi-nodes-java

<repository>
  <id>raisercostin-github</id>
  <url>https://raw.githubusercontent.com/raisercostin/maven-repo/master/</url>
  <snapshots><enabled>false</enabled></snapshots>
</repository>

Development

  • To release
    • npm run release-prepare
      npm run release-perform-local -- --releaseVersion 0.86