Initial Version
authorKai Moritz <k.moritz@extern.lvm.de>
Tue, 11 Aug 2020 06:47:23 +0000 (08:47 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 15 Aug 2020 16:18:38 +0000 (18:18 +0200)
Minimalistic project to demonstrate the serialization of an
object-graph without Jackons-Annotations.

.gitignore [new file with mode: 0644]
pom.xml [new file with mode: 0644]
src/main/java/de/juplo/examples/jackson/SerializationExample.java [new file with mode: 0644]
src/main/resources/application.properties [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..7339146
--- /dev/null
@@ -0,0 +1,31 @@
+target/
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..fb74279
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.springframework.boot</groupId>
+               <artifactId>spring-boot-starter-parent</artifactId>
+               <version>2.3.2.RELEASE</version>
+               <relativePath/> <!-- lookup parent from repository -->
+       </parent>
+       <groupId>de.juplo.examples.jackson</groupId>
+       <artifactId>noanno</artifactId>
+       <version>0.0.1-SNAPSHOT</version>
+       <name>noanno</name>
+       <description>Serialize Object-Graph without Jackson-Annotations</description>
+
+       <properties>
+               <java.version>11</java.version>
+       </properties>
+
+       <dependencies>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-databind</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>com.fasterxml.jackson.datatype</groupId>
+                       <artifactId>jackson-datatype-json-org</artifactId>
+               </dependency>
+       </dependencies>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.springframework.boot</groupId>
+                               <artifactId>spring-boot-maven-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </build>
+
+</project>
diff --git a/src/main/java/de/juplo/examples/jackson/SerializationExample.java b/src/main/java/de/juplo/examples/jackson/SerializationExample.java
new file mode 100644 (file)
index 0000000..3b2819c
--- /dev/null
@@ -0,0 +1,34 @@
+package de.juplo.examples.jackson;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SerializationExample {
+
+       public static void main(String[] args) throws Exception {
+               ObjectMapper mapper = new ObjectMapper();
+               mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+               mapper.writeValue(System.out, new Bar());
+       }
+
+       static class Foo {
+               int i = 9;
+               String str = "Hallo Welt!";
+               Map<Integer, String> map =
+                               Arrays
+                                               .asList("A", "B", null, "c", "D")
+                                               .stream()
+                                               .collect(HashMap<Integer, String>::new, (m, v) -> m.put(m.size(), v), (m, m2) -> {});
+       }
+
+       static class Bar {
+               int j = 42;
+               Foo foo = new Foo();
+       }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+