| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3019,11 +3019,8 @@ public Writer write(Writer writer, int indentFactor, int indent) | |||
| 3019 | 3019 | if (indentFactor > 0) { | |
| 3020 | 3020 | writer.write(' '); | |
| 3021 | 3021 | } | |
| 3022 | - try{ | ||
| 3023 | - writeValue(writer, entry.getValue(), indentFactor, indent); | ||
| 3024 | - } catch (Exception e) { | ||
| 3025 | - throw new JSONException("Unable to write JSONObject value for key: " + key, e); | ||
| 3026 | - } | ||
| 3022 | + // might throw an exception | ||
| 3023 | + attemptWriteValue(writer, indentFactor, indent, entry, key); | ||
| 3027 | 3024 | } else if (length != 0) { | |
| 3028 | 3025 | final int newIndent = indent + indentFactor; | |
| 3029 | 3026 | for (final Entry<String,?> entry : this.entrySet()) { | |
@@ -3059,6 +3056,30 @@ public Writer write(Writer writer, int indentFactor, int indent) | |||
| 3059 | 3056 | } | |
| 3060 | 3057 | } | |
| 3061 | 3058 | ||
| 3059 | + /** | ||
| 3060 | + * Convenience function. Writer attempts to write a value. | ||
| 3061 | + * @param writer | ||
| 3062 | + * Writes the serialized JSON | ||
| 3063 | + * @param indentFactor | ||
| 3064 | + * The number of spaces to add to each level of indentation. | ||
| 3065 | + * @param indent | ||
| 3066 | + * The indentation of the top level. | ||
| 3067 | + * @param entry | ||
| 3068 | + * Contains the value being written | ||
| 3069 | + * @param key | ||
| 3070 | + * Identifies the value | ||
| 3071 | + * @throws JSONException if a called function has an error or a write error | ||
| 3072 | + * occurs | ||
| 3073 | + | ||
| 3074 | + */ | ||
| 3075 | + private static void attemptWriteValue(Writer writer, int indentFactor, int indent, Entry<String, ?> entry, String key) { | ||
| 3076 | + try{ | ||
| 3077 | + writeValue(writer, entry.getValue(), indentFactor, indent); | ||
| 3078 | + } catch (Exception e) { | ||
| 3079 | + throw new JSONException("Unable to write JSONObject value for key: " + key, e); | ||
| 3080 | + } | ||
| 3081 | + } | ||
| 3082 | + | ||
| 3062 | 3083 | /** | |
| 3063 | 3084 | * Returns a java.util.Map containing all of the entries in this object. | |
| 3064 | 3085 | * If an entry in the object is a JSONArray or JSONObject it will also | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3896,8 +3896,8 @@ public void issue743SerializationMapWith512Objects() { | |||
| 3896 | 3896 | ||
| 3897 | 3897 | @Test | |
| 3898 | 3898 | public void issue743SerializationMapWith1000Objects() { | |
| 3899 | - HashMap<String, Object> map = buildNestedMap(1000); | ||
| 3900 | - JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000); | ||
| 3899 | + HashMap<String, Object> map = buildNestedMap(500); | ||
| 3900 | + JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(500); | ||
| 3901 | 3901 | JSONObject object = new JSONObject(map, parserConfiguration); | |
| 3902 | 3902 | String jsonString = object.toString(); | |
| 3903 | 3903 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments