diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml
index 42cb6d9..e87bfe5 100644
--- a/.github/workflows/build-main.yml
+++ b/.github/workflows/build-main.yml
@@ -10,11 +10,11 @@ jobs:
build:
strategy:
matrix:
- jdk: [ 21, 25 ]
+ tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
- TARGET_COMPATIBILITY: ${{ matrix.jdk }}
+ TARGET_COMPATIBILITY: ${{ matrix.tc }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
@@ -24,7 +24,7 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v5
with:
- java-version: ${{ matrix.jdk }}
+ java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
@@ -41,7 +41,7 @@ jobs:
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
parallel: true
- flag-name: jdk-${{ matrix.jdk }}
+ flag-name: tc${{ matrix.tc }}
- name: Publish Snapshot
run: ./gradlew -i publishToSonatype
@@ -54,4 +54,4 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
- carryforward: "jdk-21"
\ No newline at end of file
+ carryforward: "tc8"
\ No newline at end of file
diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml
index 28c14c8..5f2f61f 100644
--- a/.github/workflows/build-pr.yml
+++ b/.github/workflows/build-pr.yml
@@ -9,16 +9,16 @@ jobs:
build:
strategy:
matrix:
- jdk: [ 21, 25 ]
+ tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
- TARGET_COMPATIBILITY: ${{ matrix.jdk }}
+ TARGET_COMPATIBILITY: ${{ matrix.tc }}
steps:
- name: Setup JDK
uses: actions/setup-java@v5
with:
- java-version: ${{ matrix.jdk }}
+ java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
@@ -35,7 +35,7 @@ jobs:
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
parallel: true
- flag-name: jdk-${{ matrix.jdk }}
+ flag-name: tc${{ matrix.tc }}
coveralls-finish:
needs: build
@@ -46,4 +46,4 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
- carryforward: "jdk-21"
\ No newline at end of file
+ carryforward: "tc8"
\ No newline at end of file
diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml
index bf3bd12..0cbac3a 100644
--- a/.github/workflows/build-release.yml
+++ b/.github/workflows/build-release.yml
@@ -11,11 +11,11 @@ jobs:
build:
strategy:
matrix:
- jdk: [ 21, 25 ]
+ tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
- TARGET_COMPATIBILITY: ${{ matrix.jdk }}
+ TARGET_COMPATIBILITY: ${{ matrix.tc }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
@@ -25,7 +25,7 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v5
with:
- java-version: ${{ matrix.jdk }}
+ java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
@@ -33,9 +33,7 @@ jobs:
gradle-version: current
- name: Check out code
uses: actions/checkout@v4
- - name: Build and Test
- run: chmod +x gradlew && ./gradlew clean test
- - name: Verify Javadoc
- run: ./gradlew javadoc
- - name: Verify, Sign and Publish Release
- run: ./gradlew -i publishToSonatype closeAndReleaseSonatypeStagingRepository
+ - name: Prepare Gradle Script
+ run: chmod +x gradlew && ./gradlew
+ - name: Build, Sign and Publish Release
+ run: ./gradlew clean compileJava publishToSonatype closeAndReleaseSonatypeStagingRepository
diff --git a/README.md b/README.md
index ec8b635..2958f50 100644
--- a/README.md
+++ b/README.md
@@ -11,30 +11,34 @@ It has been extracted and repackaged from the JNATS library since it is also use
[](https://github.com/nats-io/jnats-json/actions/workflows/build-main.yml)
[](https://coveralls.io/github/nats-io/jnats-json?branch=main)
-[](https://mvnrepository.com/artifact/io.nats/jnats-json-jdk21)
+[](https://mvnrepository.com/artifact/io.nats/jnats-json)
[](https://mvnrepository.com/artifact/io.nats/jnats-json-jdk25)
-[](http://javadoc.io/doc/io.nats/jnats-json-jdk21?branch=main)
+[](http://javadoc.io/doc/io.nats/jnats-json?branch=main)
[](https://www.apache.org/licenses/LICENSE-2.0)
### JDK Version
-This project uses Java 21 Language Level api, but builds with both Java 21 and Java 25, so creates two different artifacts.
-Both have the same group id `io.nats`, and the same version but have different artifact names.
+This project uses Java 8 Language Level api, but builds jars compiled with and targeted for Java 8, 17, 21 and 25.
+It creates different artifacts for each. All have the same group id `io.nats` and the same version but have different artifact names.
-* The Java 21 artifact id is `jnats-json-jdk21`
-* The Java 25 artifact id is `jnats-json-jdk25`
+| Java Target Level | artifact id |
+|:-------------------:|------------------|
+| 8 | jnats-json |
+| 17 | jnats-json-jdk17 |
+| 21 | jnats-json-jdk21 |
+| 25 | jnats-json-jdk25 |
### Dependency Management
The NATS client is available in the Maven central repository,
and can be imported as a standard dependency in your `build.gradle` or `pom.xml` file,
-The examples shown use the jdk 21 version, to the jdk 25 version just change the artifact id.
+The examples shown use the Jdk 8 version. To use other versions, change the artifact id.
#### Gradle
```groovy
dependencies {
- implementation 'io.nats:jnats-json-jdk21:3.0.3'
+ implementation 'io.nats:jnats-json:3.0.3'
}
```
@@ -60,7 +64,7 @@ repositories {
}
dependencies {
- implementation 'io.nats:jnats-json-jdk21:3.0.4-SNAPSHOT'
+ implementation 'io.nats:jnats-json:3.0.4-SNAPSHOT'
}
```
@@ -69,7 +73,7 @@ dependencies {
```xml
io.nats
- jnats-json-jdk21
+ jnats-json
3.0.3
```
@@ -103,7 +107,7 @@ If you need a snapshot version, you must enable snapshots and change your depend
io.nats
- jnats-json-jdk21
+ jnats-json
3.0.4-SNAPSHOT
```
diff --git a/build.gradle b/build.gradle
index a4debd2..21fc630 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,20 +10,24 @@ plugins {
id("signing")
}
-def jarVersion = "3.0.3"
+def jarVersion = "3.0.4"
group = 'io.nats'
def isRelease = System.getenv("BUILD_EVENT") == "release"
def tc = System.getenv("TARGET_COMPATIBILITY")
-def targetId = tc == "25" ? "25" : "21"
-def targetJavaVersion = tc == "25" ? JavaVersion.VERSION_25 : JavaVersion.VERSION_21
-def artifact = "jnats-json-jdk" + targetId
-def bundleName = "io.nats.jnats.json.jdk" + targetId
+def targetJavaVersion = tc == null ? JavaVersion.VERSION_1_8 : JavaVersion.toVersion(tc)
+def targetId = targetJavaVersion.toString()
+def artifact = "jnats-json" + (targetJavaVersion == JavaVersion.VERSION_1_8 ? "" : "-jdk" + targetId)
+def bundleName = "io.nats.jnats.json" + (targetJavaVersion == JavaVersion.VERSION_1_8 ? "" : ".jdk" + targetId)
+
+System.out.println("targetCompatibility: " + targetId)
+System.out.println("artifact: " + artifact)
+System.out.println("bundleName: " + bundleName)
version = isRelease ? jarVersion : jarVersion + "-SNAPSHOT" // version is the variable the gradle uses.
java {
- sourceCompatibility = JavaVersion.VERSION_21
+ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = targetJavaVersion
withSourcesJar()
withJavadocJar()
diff --git a/src/main/java/io/nats/json/ArrayBuilder.java b/src/main/java/io/nats/json/ArrayBuilder.java
index 43459be..8fe9f07 100644
--- a/src/main/java/io/nats/json/ArrayBuilder.java
+++ b/src/main/java/io/nats/json/ArrayBuilder.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/DateTimeUtils.java b/src/main/java/io/nats/json/DateTimeUtils.java
index 2b7b4ef..6d6b9bb 100644
--- a/src/main/java/io/nats/json/DateTimeUtils.java
+++ b/src/main/java/io/nats/json/DateTimeUtils.java
@@ -1,6 +1,4 @@
-// Copyright 2020-2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2020-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/Encoding.java b/src/main/java/io/nats/json/Encoding.java
index fb378b8..dcc97fa 100644
--- a/src/main/java/io/nats/json/Encoding.java
+++ b/src/main/java/io/nats/json/Encoding.java
@@ -1,6 +1,4 @@
-// Copyright 2020-2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2020-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,6 +18,7 @@
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
+import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -305,7 +304,7 @@ public static StringBuilder jsonEncode(@NonNull StringBuilder sb, @Nullable Stri
* @param source the input
* @return the decoded URI
*/
- public static String uriDecode(@NonNull String source) {
- return URLDecoder.decode(source.replace("+", "%2B"), StandardCharsets.UTF_8);
+ public static String uriDecode(@NonNull String source) throws UnsupportedEncodingException {
+ return URLDecoder.decode(source.replace("+", "%2B"), StandardCharsets.UTF_8.name());
}
}
diff --git a/src/main/java/io/nats/json/JsonParseException.java b/src/main/java/io/nats/json/JsonParseException.java
index 75b21ad..fc0d115 100644
--- a/src/main/java/io/nats/json/JsonParseException.java
+++ b/src/main/java/io/nats/json/JsonParseException.java
@@ -1,6 +1,4 @@
-// Copyright 2023 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2023-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/JsonParser.java b/src/main/java/io/nats/json/JsonParser.java
index 90fc5fa..fe1f666 100644
--- a/src/main/java/io/nats/json/JsonParser.java
+++ b/src/main/java/io/nats/json/JsonParser.java
@@ -1,6 +1,4 @@
-// Copyright 2023 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2023-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/JsonSerializable.java b/src/main/java/io/nats/json/JsonSerializable.java
index 7cb3b34..4054a5f 100644
--- a/src/main/java/io/nats/json/JsonSerializable.java
+++ b/src/main/java/io/nats/json/JsonSerializable.java
@@ -1,6 +1,4 @@
-// Copyright 2021-2023 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2021-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/JsonValue.java b/src/main/java/io/nats/json/JsonValue.java
index 7c535f2..e7958e2 100644
--- a/src/main/java/io/nats/json/JsonValue.java
+++ b/src/main/java/io/nats/json/JsonValue.java
@@ -1,6 +1,4 @@
-// Copyright 2023 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2023-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -159,7 +157,7 @@ public class JsonValue implements JsonSerializable {
* A list of field names used for ordering the fields when resolving toJson,
* when the object is a map
*/
- @Nullable
+ @NonNull
public final List mapOrder;
/**
@@ -168,23 +166,50 @@ public class JsonValue implements JsonSerializable {
* @return a JsonValue
*/
public static JsonValue instance(Object o) {
- return switch (o) {
- case null -> JsonValue.NULL;
- case String string -> new JsonValue(string);
- case JsonValue jsonValue -> jsonValue;
- case JsonSerializable jsonSerializable -> jsonSerializable.toJsonValue();
- case Boolean b -> new JsonValue(b);
- case Integer i -> new JsonValue(i);
- case Long l -> new JsonValue(l);
- case Double d -> new JsonValue(d);
- case Float v -> new JsonValue(v);
- case BigDecimal bigDecimal -> new JsonValue(bigDecimal);
- case BigInteger bigInteger -> new JsonValue(bigInteger);
- case Collection> list -> _instance(list);
- case Map, ?> map -> _instance(map);
- case Duration dur -> new JsonValue(dur.toNanos());
- default -> new JsonValue(o.toString());
- };
+ if (o == null) {
+ return JsonValue.NULL;
+ }
+ if (o instanceof JsonValue) {
+ return (JsonValue)o;
+ }
+ if (o instanceof JsonSerializable) {
+ return ((JsonSerializable)o).toJsonValue();
+ }
+ if (o instanceof Map, ?>) {
+ return _instance((Map, ?>)o);
+ }
+ if (o instanceof Collection>) {
+ return _instance((Collection>)o);
+ }
+ if (o instanceof String) {
+ String s = ((String)o).trim();
+ return new JsonValue(s);
+ }
+ if (o instanceof Boolean) {
+ return new JsonValue((Boolean)o);
+ }
+ if (o instanceof Integer) {
+ return new JsonValue((Integer)o);
+ }
+ if (o instanceof Long) {
+ return new JsonValue((Long)o);
+ }
+ if (o instanceof Double) {
+ return new JsonValue((Double)o);
+ }
+ if (o instanceof Float) {
+ return new JsonValue((Float)o);
+ }
+ if (o instanceof BigDecimal) {
+ return new JsonValue((BigDecimal)o);
+ }
+ if (o instanceof BigInteger) {
+ return new JsonValue((BigInteger)o);
+ }
+ if (o instanceof Duration) {
+ return new JsonValue(((Duration)o).toNanos());
+ }
+ return new JsonValue(o.toString());
}
private static JsonValue _instance(Collection> list) {
@@ -212,7 +237,7 @@ public JsonValue(String string) {
}
/**
- * Create a JsonValue from a character. It becomes JsonValueType.STRING
+ * Create a JsonValue from a character. It becomes {@code JsonValueType.STRING}
* @param c the character
*/
public JsonValue(char c) {
@@ -311,7 +336,7 @@ private JsonValue(@Nullable String string,
@Nullable Collection array)
{
this.map = map;
- this.mapOrder = map == null ? null : new ArrayList<>();
+ this.mapOrder = new ArrayList<>();
this.array = array == null ? null : new ArrayList<>(array);
this.string = string;
this.bool = bool;
@@ -412,31 +437,27 @@ else if (type == JsonValueType.ARRAY) {
}
public void setMapOrder(String... keys) {
- if (mapOrder == null) {
+ if (type != JsonValueType.MAP) {
throw new IllegalStateException("JsonValue does not represent a map.");
}
mapOrder.clear();
if (keys != null) {
- for (String key : keys) {
- mapOrder.add(key);
- }
+ Collections.addAll(mapOrder, keys);
}
}
public void setMapOrder(List keys) {
- if (mapOrder == null) {
+ if (type != JsonValueType.MAP) {
throw new IllegalStateException("JsonValue does not represent a map.");
}
mapOrder.clear();
if (keys != null) {
- for (String key : keys) {
- mapOrder.add(key);
- }
+ mapOrder.addAll(keys);
}
}
public void addMapOrder(String key) {
- if (mapOrder == null) {
+ if (type != JsonValueType.MAP) {
throw new IllegalStateException("JsonValue does not represent a map.");
}
mapOrder.add(key);
@@ -471,23 +492,23 @@ public JsonValue toJsonValue() {
return this;
}
- @SuppressWarnings("DataFlowIssue") // by checking the type we know what the backing item is
+ @SuppressWarnings("DataFlowIssue") // we check the type and know the backing item is not null
@Override
@NonNull
public String toJson() {
- return switch (type) {
- case STRING -> QUOTE + jsonEncode(string) + QUOTE;
- case BOOL -> Boolean.toString(bool).toLowerCase();
- case MAP -> mapString();
- case ARRAY -> listString();
- case INTEGER -> i.toString();
- case LONG -> l.toString();
- case DOUBLE -> d.toString();
- case FLOAT -> f.toString();
- case BIG_DECIMAL -> bd.toString();
- case BIG_INTEGER -> bi.toString();
- default -> NULL_STR;
- };
+ switch (type) {
+ case STRING: return QUOTE + jsonEncode(string) + QUOTE;
+ case BOOL: return Boolean.toString(bool).toLowerCase();
+ case MAP: return mapString();
+ case ARRAY: return listString();
+ case INTEGER: return i.toString();
+ case LONG: return l.toString();
+ case DOUBLE: return d.toString();
+ case FLOAT: return f.toString();
+ case BIG_DECIMAL: return bd.toString();
+ case BIG_INTEGER: return bi.toString();
+ default: return NULL_STR;
+ }
}
@SuppressWarnings("DataFlowIssue") // by checking the type we know that the map is not null
@@ -516,7 +537,7 @@ private String listString() {
return JsonWriteUtils.endArray(sba).toString();
}
- @SuppressWarnings("DataFlowIssue") // can't be TYPE if type value was null
+ @SuppressWarnings("DataFlowIssue") // by checking the type we know that the value is not null
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -526,38 +547,39 @@ public boolean equals(Object o) {
if (type != jsonValue.type) return false;
- return switch (type) {
- case STRING -> string.equals(jsonValue.string);
- case BOOL -> bool.equals(jsonValue.bool);
- case INTEGER -> i.equals(jsonValue.i);
- case LONG -> l.equals(jsonValue.l);
- case DOUBLE -> d.equals(jsonValue.d);
- case FLOAT -> f.equals(jsonValue.f);
- case BIG_DECIMAL -> bd.equals(jsonValue.bd);
- case BIG_INTEGER -> bi.equals(jsonValue.bi);
- case MAP -> map.equals(jsonValue.map);
- case ARRAY -> array.equals(jsonValue.array);
- case NULL -> true; // null has null value, type was already checked.
- };
+ switch (type) {
+ case STRING: return string.equals(jsonValue.string);
+ case BOOL: return bool.equals(jsonValue.bool);
+ case INTEGER: return i.equals(jsonValue.i);
+ case LONG: return l.equals(jsonValue.l);
+ case DOUBLE: return d.equals(jsonValue.d);
+ case FLOAT: return f.equals(jsonValue.f);
+ case BIG_DECIMAL: return bd.equals(jsonValue.bd);
+ case BIG_INTEGER: return bi.equals(jsonValue.bi);
+ case MAP: return map.equals(jsonValue.map);
+ case ARRAY: return array.equals(jsonValue.array);
+ case NULL: return true; // null has null value, type was already checked.
+ }
+ return false;
}
- @SuppressWarnings("DataFlowIssue") // can't be TYPE if type value was null
+ @SuppressWarnings("DataFlowIssue") // by checking the type we know that the value is not null
@Override
public int hashCode() {
- return (31 *
- switch (type) {
- case STRING -> string.hashCode();
- case BOOL -> bool.hashCode();
- case INTEGER -> i.hashCode();
- case LONG -> l.hashCode();
- case DOUBLE -> d.hashCode();
- case FLOAT -> f.hashCode();
- case BIG_DECIMAL -> bd.hashCode();
- case BIG_INTEGER -> bi.hashCode();
- case MAP -> map.hashCode();
- case ARRAY -> array.hashCode();
- default -> 0;
- })
- + type.hashCode();
+
+ int hc = 0;
+ switch (type) {
+ case STRING: hc = string.hashCode(); break;
+ case BOOL: hc = bool.hashCode(); break;
+ case INTEGER: hc = i.hashCode(); break;
+ case LONG: hc = l.hashCode(); break;
+ case DOUBLE: hc = d.hashCode(); break;
+ case FLOAT: hc = f.hashCode(); break;
+ case BIG_DECIMAL: hc = bd.hashCode(); break;
+ case BIG_INTEGER: hc = bi.hashCode(); break;
+ case MAP: hc = map.hashCode(); break;
+ case ARRAY: hc = array.hashCode(); break;
+ }
+ return 31 * hc + type.hashCode();
}
}
diff --git a/src/main/java/io/nats/json/JsonValueSupplier.java b/src/main/java/io/nats/json/JsonValueSupplier.java
index 7922217..cd83501 100644
--- a/src/main/java/io/nats/json/JsonValueSupplier.java
+++ b/src/main/java/io/nats/json/JsonValueSupplier.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/JsonValueType.java b/src/main/java/io/nats/json/JsonValueType.java
index fd8a834..15a1a6b 100644
--- a/src/main/java/io/nats/json/JsonValueType.java
+++ b/src/main/java/io/nats/json/JsonValueType.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -71,5 +71,5 @@ public enum JsonValueType {
/**
* Type for a JsonValue of a null
*/
- NULL;
+ NULL
}
diff --git a/src/main/java/io/nats/json/JsonValueUtils.java b/src/main/java/io/nats/json/JsonValueUtils.java
index 30fafa3..2d91ad3 100644
--- a/src/main/java/io/nats/json/JsonValueUtils.java
+++ b/src/main/java/io/nats/json/JsonValueUtils.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/main/java/io/nats/json/JsonWriteUtils.java b/src/main/java/io/nats/json/JsonWriteUtils.java
index 5ac993f..c0e9b5a 100644
--- a/src/main/java/io/nats/json/JsonWriteUtils.java
+++ b/src/main/java/io/nats/json/JsonWriteUtils.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -380,14 +380,14 @@ public static void addField(@NonNull StringBuilder sb, @NonNull String fieldName
/**
* ListValueResolver implementation for a list of Strings
*/
- public static ListValueResolver STRING_LIST_RESOLVER = new ListValueResolver<>() {
+ public static ListValueResolver STRING_LIST_RESOLVER = new ListValueResolver() {
@Override
public boolean appendable(@Nullable String s) {
return s != null && !s.isEmpty();
}
@Override
- public void append(@NonNull StringBuilder sb, @Nullable String s) {
+ public void append(@NonNull StringBuilder sb, @NonNull String s) {
sb.append(Q);
jsonEncode(sb, s);
sb.append(Q);
diff --git a/src/main/java/io/nats/json/ListValueResolver.java b/src/main/java/io/nats/json/ListValueResolver.java
index ec9459b..678fc3c 100644
--- a/src/main/java/io/nats/json/ListValueResolver.java
+++ b/src/main/java/io/nats/json/ListValueResolver.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -40,5 +40,5 @@ default boolean appendable(@Nullable T t) {
* @param sb the target StringBuilder
* @param t the object
*/
- void append(@NonNull StringBuilder sb, @Nullable T t);
+ void append(@NonNull StringBuilder sb, @NonNull T t);
}
diff --git a/src/main/java/io/nats/json/MapBuilder.java b/src/main/java/io/nats/json/MapBuilder.java
index 1e00e8a..043b0cd 100644
--- a/src/main/java/io/nats/json/MapBuilder.java
+++ b/src/main/java/io/nats/json/MapBuilder.java
@@ -1,4 +1,4 @@
-// Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -57,7 +57,6 @@ public static MapBuilder instance() {
public MapBuilder put(@NonNull String key, @Nullable Object value) {
//noinspection DataFlowIssue // NO ISSUE, WE KNOW jv.map is NOT NULL
jv.map.put(key, JsonValue.instance(value));
- //noinspection DataFlowIssue // NO ISSUE, WE KNOW jv.mapOrder is NOT NULL
jv.mapOrder.add(key);
return this;
}
@@ -75,7 +74,6 @@ public MapBuilder putEntries(@Nullable Map map) {
String key = entry.getKey();
//noinspection DataFlowIssue // NO ISSUE, WE KNOW jv.map is NOT NULL
jv.map.put(key, JsonValue.instance(entry.getValue()));
- //noinspection DataFlowIssue // NO ISSUE, WE KNOW jv.mapOrder is NOT NULL
jv.mapOrder.add(key);
}
}
diff --git a/src/test/java/io/nats/json/DateTimeUtilsTests.java b/src/test/java/io/nats/json/DateTimeUtilsTests.java
index a614b1b..077579e 100644
--- a/src/test/java/io/nats/json/DateTimeUtilsTests.java
+++ b/src/test/java/io/nats/json/DateTimeUtilsTests.java
@@ -1,6 +1,4 @@
-// Copyright 2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/test/java/io/nats/json/EncodingTests.java b/src/test/java/io/nats/json/EncodingTests.java
index 8b48685..60e52c5 100644
--- a/src/test/java/io/nats/json/EncodingTests.java
+++ b/src/test/java/io/nats/json/EncodingTests.java
@@ -1,6 +1,4 @@
-// Copyright 2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,9 +17,9 @@
import io.ResourceUtils;
import org.junit.jupiter.api.Test;
+import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import java.util.Objects;
import static io.nats.json.Encoding.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@@ -70,7 +68,12 @@ private void _testJsonEncodeDecode(String encodedInput, String targetDecode, Str
String decoded = jsonDecode(encodedInput);
assertEquals(targetDecode, decoded);
String encoded = jsonEncode(new StringBuilder(), decoded).toString();
- assertEquals(Objects.requireNonNullElse(targetEncode, encodedInput), encoded);
+ if (targetEncode == null) {
+ assertEquals(encodedInput, encoded);
+ }
+ else {
+ assertEquals(targetEncode, encoded);
+ }
}
@Test
@@ -123,7 +126,7 @@ public void testBase64BasicEncoding() {
}
@Test
- public void testBase64UrlEncoding() {
+ public void testBase64UrlEncoding() throws UnsupportedEncodingException {
String text = "blahblah";
byte[] btxt = text.getBytes();
String surl = "https://nats.io/";
diff --git a/src/test/java/io/nats/json/JsonParsingTests.java b/src/test/java/io/nats/json/JsonParsingTests.java
index fd52ab0..7046a29 100644
--- a/src/test/java/io/nats/json/JsonParsingTests.java
+++ b/src/test/java/io/nats/json/JsonParsingTests.java
@@ -1,6 +1,4 @@
-// Copyright 2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -265,7 +263,11 @@ public void testArray() throws JsonParseException {
List mappedList2 = parse(new JsonValue(mappedList).toJson()).array;
List mappedArray = new JsonValue(list.toArray(new JsonValue[0])).array;
List mappedArray2 = parse(new JsonValue(list.toArray(new JsonValue[0])).toJson()).array;
- for (int i = 0; i < list.size(); i++) {
+ assertNotNull(mappedList);
+ assertNotNull(mappedList2);
+ assertNotNull(mappedArray);
+ assertNotNull(mappedArray2);
+ for (int i = 0; i < mappedList.size(); i++) {
JsonValue v = list.get(i);
JsonValue lv = mappedList.get(i);
JsonValue lv2 = mappedList2.get(i);
@@ -393,7 +395,7 @@ public void testParsingCoverage() throws JsonParseException {
assertNotNull(v);
assertNotNull(v.array);
assertEquals(1, v.array.size());
- assertEquals("foo", v.array.getFirst().string);
+ assertEquals("foo", v.array.get(0).string);
String s = "foo \b \t \n \f \r \" \\ /";
String j = "\"" + jsonEncode(s) + "\"";
diff --git a/src/test/java/io/nats/json/JsonUnicodeParsingTest.java b/src/test/java/io/nats/json/JsonUnicodeParsingTest.java
index e165e0e..0b83763 100644
--- a/src/test/java/io/nats/json/JsonUnicodeParsingTest.java
+++ b/src/test/java/io/nats/json/JsonUnicodeParsingTest.java
@@ -1,6 +1,4 @@
-// Copyright 2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/src/test/java/io/nats/json/JsonValueUtilsTests.java b/src/test/java/io/nats/json/JsonValueUtilsTests.java
index 77c27b9..57d72ad 100644
--- a/src/test/java/io/nats/json/JsonValueUtilsTests.java
+++ b/src/test/java/io/nats/json/JsonValueUtilsTests.java
@@ -1,6 +1,4 @@
-// Copyright 2020-2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2020-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -332,7 +330,7 @@ public void testConvertToList() {
});
assertEquals(1, strings.size());
- assertEquals(STRING_STRING, strings.getFirst());
+ assertEquals(STRING_STRING, strings.get(0));
}
@Test
@@ -578,6 +576,7 @@ private static void validateNotFoundOrWrongType(
@Test
public void testGetIntLong() {
JsonValue x = readValue(TEST_JV, STRING);
+ assertNotNull(x);
JsonValue i = new JsonValue(Integer.MAX_VALUE);
JsonValue li = new JsonValue((long)Integer.MAX_VALUE);
JsonValue lmax = new JsonValue(Long.MAX_VALUE);
diff --git a/src/test/java/io/nats/json/JsonWriteUtilsTests.java b/src/test/java/io/nats/json/JsonWriteUtilsTests.java
index b896fc9..a457e18 100644
--- a/src/test/java/io/nats/json/JsonWriteUtilsTests.java
+++ b/src/test/java/io/nats/json/JsonWriteUtilsTests.java
@@ -1,6 +1,4 @@
-// Copyright 2025 The NATS Authors
-//
-// Modifications Copyright 2025-2026 Synadia Communications, Inc.
+// Copyright 2025-2026 The NATS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.