From b7787a7f78add2558bf650be7dbaf6754906cc90 Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Tue, 11 Jun 2024 08:47:10 -0700 Subject: [PATCH] partial revert of PR #2060 (JSON parser abstraction) (#2278) --- jme3-examples/build.gradle | 4 ++-- jme3-plugins/build.gradle | 3 +-- .../plugins/gltf/CustomContentManager.java | 7 +++--- .../scene/plugins/gltf/ExtensionLoader.java | 5 ++-- .../jme3/scene/plugins/gltf/ExtrasLoader.java | 3 ++- .../jme3/scene/plugins/gltf/GltfLoader.java | 14 ++++++----- .../jme3/scene/plugins/gltf/GltfUtils.java | 23 ++++--------------- .../gltf/LightsPunctualExtensionLoader.java | 8 +++---- .../PBREmissiveStrengthExtensionLoader.java | 4 ++-- .../gltf/PBRSpecGlossExtensionLoader.java | 4 ++-- .../gltf/TextureTransformExtensionLoader.java | 8 +++---- .../plugins/gltf/UnlitExtensionLoader.java | 5 ++-- .../scene/plugins/gltf/UserDataLoader.java | 10 ++++---- 13 files changed, 43 insertions(+), 55 deletions(-) diff --git a/jme3-examples/build.gradle b/jme3-examples/build.gradle index b5979feceb..c51b2ae522 100644 --- a/jme3-examples/build.gradle +++ b/jme3-examples/build.gradle @@ -24,8 +24,8 @@ dependencies { implementation project(':jme3-networking') implementation project(':jme3-niftygui') implementation project(':jme3-plugins') - implementation project(':jme3-plugins-json') - implementation project(':jme3-plugins-json-gson') +// implementation project(':jme3-plugins-json') +// implementation project(':jme3-plugins-json-gson') implementation project(':jme3-terrain') implementation project(':jme3-awt-dialogs') runtimeOnly project(':jme3-testdata') diff --git a/jme3-plugins/build.gradle b/jme3-plugins/build.gradle index 1d325314ee..b88f0a64fd 100644 --- a/jme3-plugins/build.gradle +++ b/jme3-plugins/build.gradle @@ -11,7 +11,6 @@ sourceSets { dependencies { api project(':jme3-core') - implementation project(':jme3-plugins-json') - implementation project(':jme3-plugins-json-gson') + api 'com.google.code.gson:gson:2.9.1' testRuntimeOnly project(':jme3-desktop') } diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/CustomContentManager.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/CustomContentManager.java index c713a72b58..df612f1a0a 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/CustomContentManager.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/CustomContentManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2023 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,10 +31,9 @@ */ package com.jme3.scene.plugins.gltf; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.jme3.asset.AssetLoadException; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonElement; - import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtensionLoader.java index 033b200378..c3bd71f394 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,8 +31,7 @@ */ package com.jme3.scene.plugins.gltf; - -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonElement; import java.io.IOException; /** diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtrasLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtrasLoader.java index 3c4c9819dc..c470478db1 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtrasLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/ExtrasLoader.java @@ -30,7 +30,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonElement; + +import com.google.gson.JsonElement; /** * Interface to handle a glTF extra. diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java index 46adacd386..e4e308355d 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2023 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,10 +31,12 @@ */ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonObject; -import com.jme3.plugins.json.JsonPrimitive; -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.stream.JsonReader; import com.jme3.anim.*; import com.jme3.asset.*; import com.jme3.material.Material; @@ -121,7 +123,7 @@ protected Object loadFromStream(AssetInfo assetInfo, InputStream stream) throws defaultMat.setFloat("Roughness", 1f); } - docRoot = parse(stream); + docRoot = JsonParser.parseReader(new JsonReader(new InputStreamReader(stream))).getAsJsonObject(); JsonObject asset = docRoot.getAsJsonObject().get("asset").getAsJsonObject(); getAsString(asset, "generator"); diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfUtils.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfUtils.java index e67ed37430..0af3321aab 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfUtils.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,15 +31,13 @@ */ package com.jme3.scene.plugins.gltf; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetLoadException; import com.jme3.math.*; import com.jme3.scene.*; -import com.jme3.plugins.json.Json; -import com.jme3.plugins.json.JsonParser; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonObject; -import com.jme3.plugins.json.JsonElement; import com.jme3.texture.Texture; import com.jme3.util.*; import java.io.*; @@ -61,18 +59,7 @@ public class GltfUtils { private GltfUtils() { } - - /** - * Parse a json input stream and returns a {@link JsonObject} - * @param stream the stream to parse - * @return the JsonObject - */ - public static JsonObject parse(InputStream stream) { - JsonParser parser = Json.create(); - return parser.parse(stream); - } - - public static Mesh.Mode getMeshMode(Integer mode) { + public static Mesh.Mode getMeshMode(Integer mode) { if (mode == null) { return Mesh.Mode.Triangles; } diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/LightsPunctualExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/LightsPunctualExtensionLoader.java index b3df7dbc88..26d664ed82 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/LightsPunctualExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/LightsPunctualExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,9 +31,9 @@ */ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonObject; -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.jme3.asset.AssetLoadException; import com.jme3.light.DirectionalLight; import com.jme3.light.Light; diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBREmissiveStrengthExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBREmissiveStrengthExtensionLoader.java index ae7cb45c2c..c08d132307 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBREmissiveStrengthExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBREmissiveStrengthExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 jMonkeyEngine + * Copyright (c) 2023-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ package com.jme3.scene.plugins.gltf; import com.jme3.asset.AssetKey; -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonElement; import java.io.IOException; /** diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRSpecGlossExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRSpecGlossExtensionLoader.java index 2ab3862db3..7eca101de3 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRSpecGlossExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRSpecGlossExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,7 +34,7 @@ import com.jme3.asset.AssetKey; import java.io.IOException; -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonElement; import static com.jme3.scene.plugins.gltf.GltfUtils.getAsColor; import static com.jme3.scene.plugins.gltf.GltfUtils.getAsFloat; diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TextureTransformExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TextureTransformExtensionLoader.java index ea643cea0c..ecbcd2519f 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TextureTransformExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TextureTransformExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2022 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,9 +31,9 @@ */ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonObject; -import com.jme3.plugins.json.JsonElement; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.jme3.asset.AssetLoadException; import com.jme3.math.Matrix3f; import com.jme3.math.Vector3f; diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UnlitExtensionLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UnlitExtensionLoader.java index cb45fcc533..620c7f7e45 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UnlitExtensionLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UnlitExtensionLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonElement; + +import com.google.gson.JsonElement; import com.jme3.asset.AssetKey; /** diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UserDataLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UserDataLoader.java index df62f51685..5045f71b1b 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UserDataLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UserDataLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2023 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,10 +32,10 @@ package com.jme3.scene.plugins.gltf; -import com.jme3.plugins.json.JsonArray; -import com.jme3.plugins.json.JsonElement; -import com.jme3.plugins.json.JsonObject; -import com.jme3.plugins.json.JsonPrimitive; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import com.jme3.scene.Spatial; import java.lang.reflect.Array;