This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference to uk.com.robust-it has been removed. Instead CloneUtils cl…
…ass now simply mimics behaviour of native deepCopy methods defined in JsonObject, JsonArray, JsonPrimitive and JsonNull.
- Loading branch information
Phil Filonov
committed
May 4, 2016
1 parent
250dbe6
commit 45b3bb1
Showing
6 changed files
with
49 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
jest-common/src/main/java/io/searchbox/cloning/CloneUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.searchbox.cloning; | ||
|
||
import com.google.gson.*; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This class is just a workaround for the non-public deepCopy methods in Gson. | ||
*/ | ||
public class CloneUtils { | ||
public static JsonElement deepClone(JsonElement jsonElement) { | ||
if (jsonElement instanceof JsonObject) { | ||
return deepCloneObject(jsonElement); | ||
} else if (jsonElement instanceof JsonArray) { | ||
return deepCloneArray(jsonElement); | ||
} else if (jsonElement instanceof JsonPrimitive) { | ||
return jsonElement; | ||
} | ||
|
||
return JsonNull.INSTANCE; | ||
} | ||
|
||
private static JsonElement deepCloneObject(JsonElement jsonElement) { | ||
JsonObject jsonObject = (JsonObject) jsonElement; | ||
JsonObject result = new JsonObject(); | ||
|
||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { | ||
result.add(entry.getKey(), deepClone(entry.getValue())); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static JsonElement deepCloneArray(JsonElement jsonElement) { | ||
JsonArray jsonArray = (JsonArray) jsonElement; | ||
JsonArray result = new JsonArray(); | ||
|
||
for (JsonElement element : jsonArray) { | ||
result.add(deepClone(element)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
jest-common/src/main/java/io/searchbox/gson/GsonUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters