diff --git a/base/src/main/java/io/spine/json/Json.java b/base/src/main/java/io/spine/json/Json.java index 04d6d1c519..aaef754d7c 100644 --- a/base/src/main/java/io/spine/json/Json.java +++ b/base/src/main/java/io/spine/json/Json.java @@ -39,6 +39,17 @@ /** * Utilities for working with JSON. + * + *
Both {@linkplain #toJson(Message) parsing} and {@linkplain #fromJson(String, Class) printing} + * functionality acknowledges presence of the custom Protobuf message types relying on + * the {@link KnownTypes} for this. + * + *
The parsing functionality follows the default Protobuf ignorance strategy for unknown fields, + * i.e. the unknown fields are {@linkplain Parser#ignoringUnknownFields() ignored} when a JSON + * string is parsed. + * + * @see + * Protobuf Unknown Fields */ public final class Json { @@ -46,7 +57,8 @@ public final class Json { .typeRegistry(); private static final Printer PRINTER = printer().usingTypeRegistry(typeRegistry); private static final Printer COMPACT_PRINTER = PRINTER.omittingInsignificantWhitespace(); - private static final Parser PARSER = parser().usingTypeRegistry(typeRegistry); + private static final Parser PARSER = parser().ignoringUnknownFields() + .usingTypeRegistry(typeRegistry); /** * Prevents the utility class instantiation. @@ -57,7 +69,8 @@ private Json() { /** * Converts passed message into Json representation. * - * @param message the message object + * @param message + * the message object * @return JSON string */ public static String toJson(Message message) { @@ -70,7 +83,8 @@ public static String toJson(Message message) { * *
The resulted JSON does not contain the line separators.
*
- * @param message the {@code Message} object
+ * @param message
+ * the {@code Message} object
* @return the converted message to JSON
*/
public static String toCompactJson(Message message) {
diff --git a/base/src/test/java/io/spine/json/JsonTest.java b/base/src/test/java/io/spine/json/JsonTest.java
index 79c7a80da3..c51049bd04 100644
--- a/base/src/test/java/io/spine/json/JsonTest.java
+++ b/base/src/test/java/io/spine/json/JsonTest.java
@@ -101,7 +101,17 @@ void printCompact() {
@DisplayName("parse from JSON")
void parse() {
String idValue = newUuid();
- String jsonMessage = format("{value:%s}", idValue);
+ String jsonMessage = format("{\"value\": \"%s\"}", idValue);
+ WrappedString parsedValue = fromJson(jsonMessage, WrappedString.class);
+ assertNotNull(parsedValue);
+ assertEquals(idValue, parsedValue.getValue());
+ }
+
+ @Test
+ @DisplayName("parse from JSON with unknown values")
+ void parseUnknown() {
+ String idValue = newUuid();
+ String jsonMessage = format("{\"value\": \"%s\", \"newField\": \"newValue\"}", idValue);
WrappedString parsedValue = fromJson(jsonMessage, WrappedString.class);
assertNotNull(parsedValue);
assertEquals(idValue, parsedValue.getValue());
diff --git a/license-report.md b/license-report.md
index ab6e0e281c..54c09913c9 100644
--- a/license-report.md
+++ b/license-report.md
@@ -1,6 +1,6 @@
-# Dependencies of `io.spine:spine-base:1.5.0`
+# Dependencies of `io.spine:spine-base:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -330,12 +330,12 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:31 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:50 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-errorprone-checks:1.5.0`
+# Dependencies of `io.spine.tools:spine-errorprone-checks:1.5.1`
## Runtime
1. **Group:** com.github.ben-manes.caffeine **Name:** caffeine **Version:** 2.7.0
@@ -777,12 +777,12 @@ This report was generated on **Sat Mar 07 22:00:31 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:32 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:51 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-javadoc-filter:1.5.0`
+# Dependencies of `io.spine.tools:spine-javadoc-filter:1.5.1`
## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1170,12 +1170,12 @@ This report was generated on **Sat Mar 07 22:00:32 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:32 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:51 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-javadoc-prettifier:1.5.0`
+# Dependencies of `io.spine.tools:spine-javadoc-prettifier:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -1537,12 +1537,12 @@ This report was generated on **Sat Mar 07 22:00:32 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:33 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-model-compiler:1.5.0`
+# Dependencies of `io.spine.tools:spine-model-compiler:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -1920,12 +1920,12 @@ This report was generated on **Sat Mar 07 22:00:33 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-mute-logging:1.5.0`
+# Dependencies of `io.spine.tools:spine-mute-logging:1.5.1`
## Runtime
1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3
@@ -2305,12 +2305,12 @@ This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-plugin-base:1.5.0`
+# Dependencies of `io.spine.tools:spine-plugin-base:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -2672,12 +2672,12 @@ This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-plugin-testlib:1.5.0`
+# Dependencies of `io.spine.tools:spine-plugin-testlib:1.5.1`
## Runtime
1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3
@@ -3097,12 +3097,12 @@ This report was generated on **Sat Mar 07 22:00:34 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:35 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-proto-dart-plugin:1.5.0`
+# Dependencies of `io.spine.tools:spine-proto-dart-plugin:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -3464,12 +3464,12 @@ This report was generated on **Sat Mar 07 22:00:35 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-proto-js-plugin:1.5.0`
+# Dependencies of `io.spine.tools:spine-proto-js-plugin:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -3831,12 +3831,12 @@ This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-protoc-api:1.5.0`
+# Dependencies of `io.spine.tools:spine-protoc-api:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -4158,12 +4158,12 @@ This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-protoc-plugin:1.5.0`
+# Dependencies of `io.spine.tools:spine-protoc-plugin:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -4493,12 +4493,12 @@ This report was generated on **Sat Mar 07 22:00:36 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:37 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine:spine-testlib:1.5.0`
+# Dependencies of `io.spine:spine-testlib:1.5.1`
## Runtime
1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3
@@ -4878,12 +4878,12 @@ This report was generated on **Sat Mar 07 22:00:37 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:37 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-tool-base:1.5.0`
+# Dependencies of `io.spine.tools:spine-tool-base:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -5213,12 +5213,12 @@ This report was generated on **Sat Mar 07 22:00:37 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:38 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
+This report was generated on **Thu Mar 12 11:36:55 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
-# Dependencies of `io.spine.tools:spine-validation-generator:1.5.0`
+# Dependencies of `io.spine.tools:spine-validation-generator:1.5.1`
## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -5548,4 +5548,4 @@ This report was generated on **Sat Mar 07 22:00:38 EET 2020** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
-This report was generated on **Sat Mar 07 22:00:38 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
\ No newline at end of file
+This report was generated on **Thu Mar 12 11:36:55 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index e3838f4e0b..dc02883fd6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.