diff --git a/.circleci/config.yml b/.circleci/config.yml index ce5855b..2cb624d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,11 +16,20 @@ workflows: - test-linux: name: Java 11 - Linux - OpenJDK docker-image: cimg/openjdk:11.0 + requires: + - build-linux + - test-linux: + name: Java 17 - Linux - OpenJDK + docker-image: cimg/openjdk:17.0 with-coverage: true requires: - build-linux - build-test-windows: name: Java 11 - Windows - OpenJDK + openjdk-version: 11.0.2.01 + - build-test-windows: + name: Java 17 - Windows - OpenJDK + openjdk-version: 17.0.1 - build-test-android: name: Android @@ -86,17 +95,20 @@ jobs: path: coverage build-test-windows: + parameters: + openjdk-version: + type: string executor: name: win/vs2019 shell: powershell.exe steps: - checkout + - run: + name: uninstall previous openjdk + command: choco uninstall openjdk - run: name: install OpenJDK - command: | - $ProgressPreference = "SilentlyContinue" # prevents console errors from CircleCI host - iwr -outf openjdk.msi https://developers.redhat.com/download-manager/file/java-11-openjdk-11.0.5.10-2.windows.redhat.x86_64.msi - Start-Process msiexec.exe -Wait -ArgumentList '/I openjdk.msi /quiet' + command: choco install openjdk --version <> - run: name: build and test command: | diff --git a/build-android.gradle b/build-android.gradle index 9c48943..0329994 100644 --- a/build-android.gradle +++ b/build-android.gradle @@ -6,7 +6,6 @@ buildscript { mavenCentral() mavenLocal() google() - jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.2.0' diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index a0a9171..8fe36d0 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -16,5 +16,5 @@ plugins { } repositories { - jcenter() + gradlePluginPortal() } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f3d88b1..e708b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d913..2e6e589 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7..4f906e0 100755 --- a/gradlew +++ b/gradlew @@ -82,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -129,6 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 9109989..ac1b06f 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/java/com/launchdarkly/sdk/LDValue.java b/src/main/java/com/launchdarkly/sdk/LDValue.java index 956dc7f..bf36572 100644 --- a/src/main/java/com/launchdarkly/sdk/LDValue.java +++ b/src/main/java/com/launchdarkly/sdk/LDValue.java @@ -45,8 +45,6 @@ */ @JsonAdapter(LDValueTypeAdapter.class) public abstract class LDValue implements JsonSerializable { - static final Gson gson = new Gson(); - /** * Returns the same value if non-null, or {@link #ofNull()} if null. * @@ -393,7 +391,7 @@ public LDValue get(String name) { * @return a JSON string */ public String toJsonString() { - return gson.toJson(this); + return JsonSerialization.serialize(this); } abstract void write(JsonWriter writer) throws IOException; diff --git a/src/main/java/com/launchdarkly/sdk/json/JsonSerialization.java b/src/main/java/com/launchdarkly/sdk/json/JsonSerialization.java index 8cadeb2..034717c 100644 --- a/src/main/java/com/launchdarkly/sdk/json/JsonSerialization.java +++ b/src/main/java/com/launchdarkly/sdk/json/JsonSerialization.java @@ -1,6 +1,7 @@ package com.launchdarkly.sdk.json; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.launchdarkly.sdk.EvaluationDetail; import com.launchdarkly.sdk.EvaluationReason; import com.launchdarkly.sdk.LDUser; @@ -35,7 +36,10 @@ private JsonSerialization() {} static final List> knownDeserializableClasses = new ArrayList<>(); - private static final Gson gson = new Gson(); + // This Gson instance has serializeNulls enabled because we want the decision of whether to include + // a null property value to be left up to our own serializers. The default behavior would mean that + // the GsonWriter would not allow us to write a null property value ever. + private static final Gson gson = new GsonBuilder().serializeNulls().create(); /** * Converts an object to its JSON representation. diff --git a/src/test/java/com/launchdarkly/sdk/json/JsonTestHelpers.java b/src/test/java/com/launchdarkly/sdk/json/JsonTestHelpers.java index f80546e..667dc54 100644 --- a/src/test/java/com/launchdarkly/sdk/json/JsonTestHelpers.java +++ b/src/test/java/com/launchdarkly/sdk/json/JsonTestHelpers.java @@ -15,7 +15,7 @@ @SuppressWarnings("javadoc") public abstract class JsonTestHelpers extends BaseTest { - static final Gson gson = new Gson(); + static final Gson gson = new GsonBuilder().serializeNulls().create(); // Note that when we verify the behavior of Gson with LDGson in this project's unit tests, that // is not an adequate test for whether the adapters will work in the Java SDK where there is the @@ -24,7 +24,7 @@ public abstract class JsonTestHelpers extends BaseTest { // that the adapters work correctly if Gson actually uses them. public static Gson configureGson() { - return new GsonBuilder().registerTypeAdapterFactory(LDGson.typeAdapters()).create(); + return new GsonBuilder().serializeNulls().registerTypeAdapterFactory(LDGson.typeAdapters()).create(); } public static ObjectMapper configureJacksonMapper() { diff --git a/src/test/java/com/launchdarkly/sdk/json/LDGsonTest.java b/src/test/java/com/launchdarkly/sdk/json/LDGsonTest.java index d493d8e..5f03611 100644 --- a/src/test/java/com/launchdarkly/sdk/json/LDGsonTest.java +++ b/src/test/java/com/launchdarkly/sdk/json/LDGsonTest.java @@ -63,7 +63,7 @@ public void valueMapToJsonElementMap() { public void complexObjectToJsonTree() { LDUser user = new LDUser.Builder("userkey").name("name") .custom("attr1", LDValue.ofNull()) - .custom("atrt2", LDValue.of(true)) + .custom("attr2", LDValue.of(true)) .custom("attr3", LDValue.of(false)) .custom("attr4", LDValue.of(0)) .custom("attr5", LDValue.of(1)) diff --git a/src/test/java/com/launchdarkly/sdk/json/LDValueJsonSerializationTest.java b/src/test/java/com/launchdarkly/sdk/json/LDValueJsonSerializationTest.java index 04cd551..8e443d7 100644 --- a/src/test/java/com/launchdarkly/sdk/json/LDValueJsonSerializationTest.java +++ b/src/test/java/com/launchdarkly/sdk/json/LDValueJsonSerializationTest.java @@ -31,6 +31,7 @@ public void jsonEncodingForNonNullValues() throws Exception { verifyValueSerialization(LDValue.of(2.5d), "2.5"); verifyValueSerialization(JsonTestHelpers.basicArrayValue(), "[2,\"x\"]"); verifyValueSerialization(JsonTestHelpers.basicObjectValue(), "{\"x\":2}"); + verifyValueSerialization(LDValue.buildObject().put("x", LDValue.ofNull()).build(), "{\"x\":null}"); verifyDeserializeInvalidJson(LDValue.class, "]"); }