From: Kai Moritz Date: Tue, 11 Aug 2020 06:47:23 +0000 (+0200) Subject: Initial Version X-Git-Url: https://juplo.de/gitweb/?p=demos%2Fnoanno;a=commitdiff_plain;h=ede0282954b10c864506e5683e311a9a746aff37 Initial Version Minimalistic project to demonstrate the serialization of an object-graph without Jackons-Annotations. --- ede0282954b10c864506e5683e311a9a746aff37 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7339146 --- /dev/null +++ b/.gitignore @@ -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 index 0000000..fb74279 --- /dev/null +++ b/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + de.juplo.examples.jackson + noanno + 0.0.1-SNAPSHOT + noanno + Serialize Object-Graph without Jackson-Annotations + + + 11 + + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.datatype + jackson-datatype-json-org + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + 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 index 0000000..3b2819c --- /dev/null +++ b/src/main/java/de/juplo/examples/jackson/SerializationExample.java @@ -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 map = + Arrays + .asList("A", "B", null, "c", "D") + .stream() + .collect(HashMap::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 index 0000000..8b13789 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +