From f6040c123a746e3e5ee0d3132b92323f19092f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Sun, 19 Nov 2023 16:43:36 +0100 Subject: [PATCH] #4: updated README to be consistent --- README.adoc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 562f329..e9c98a0 100644 --- a/README.adoc +++ b/README.adoc @@ -111,9 +111,10 @@ Person person = new Person(); person.setName("John Doe"); person.satAge(42); StringBuilder sb = new StringBuilder(); -StructuredWriter writer = JsonFormat.of().writer(sb); +StructuredWriter writer = StandardFormat.json().writer(sb); marshall(writer, person); -System.out.println(sb.toString()); +String json = sb.toString(); +System.out.println(json); ``` This will print the following output: @@ -124,7 +125,7 @@ This will print the following output: } ``` -The interesting fact is that you can exchange `JsonFormat.of()` with something else to get a different format without changing your implementation of `marshal`. So you can also use `XmlFormat.of()` to produce XML or you can generate YAML or even gRPC/ProtoBuf. +The interesting fact is that you can exchange `StandardFormat.json()` with something else to get a different format without changing your implementation of `marshal`. So you can also use `StandardFormat.xml()` to produce XML or you can generate YAML or even gRPC/ProtoBuf. To unmarshall a `Person` you can do something like this: @@ -151,6 +152,14 @@ public void unmarshall(StructuredReader reader, Person person) { } ``` +Now you could use it like this: +```java +Person person = new Person(); +StructuredReader reader = StandardFormat.json().reader(json); +unmarshall(reader, person); +System.out.println(person.getName() + ":" + person.getAge()); +``` + == Schemas Formats like `JSON`, `YAML`, or `XML` are generic and can be used without a schema.