Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions base/src/main/java/io/spine/json/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,26 @@

/**
* Utilities for working with JSON.
*
* <p>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.
*
* <p>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 <a href="https://developers.google.com/protocol-buffers/docs/proto3#unknowns">
* Protobuf Unknown Fields</a>
*/
public final class Json {

private static final TypeRegistry typeRegistry = KnownTypes.instance()
.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.
Expand All @@ -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) {
Expand All @@ -70,7 +83,8 @@ public static String toJson(Message message) {
*
* <p>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) {
Expand Down
12 changes: 11 additions & 1 deletion base/src/test/java/io/spine/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
60 changes: 30 additions & 30 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
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).
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>

<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -154,7 +154,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-protoc-plugin</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion version.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* as we want to manage the versions in a single source.
*/

final def SPINE_VERSION = '1.5.0'
final def SPINE_VERSION = '1.5.1'

ext {
spineVersion = SPINE_VERSION
Expand Down