From 7281963d3d73ffab40188c051cf73be890b0fd56 Mon Sep 17 00:00:00 2001 From: Peter Wall Date: Wed, 3 Jul 2024 23:13:46 +1000 Subject: [PATCH] Switched to use kjson-exception --- CHANGELOG.md | 8 ++- README.md | 14 ++++-- pom.xml | 7 ++- src/main/kotlin/io/kjson/JSONException.kt | 50 ------------------- src/main/kotlin/io/kjson/JSONTypeException.kt | 2 +- .../kotlin/io/kjson/parser/ParseException.kt | 12 ++++- .../kotlin/io/kjson/parser/ParserConstants.kt | 1 + 7 files changed, 34 insertions(+), 60 deletions(-) delete mode 100644 src/main/kotlin/io/kjson/JSONException.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index dde27af..e066a4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). +## [8.1] - 2024-07-03 +### Changed +- `JSONTypeException`, `ParseException`, `pom.xml`: switched to use `kjson-exception` +### Removed +- `JSONException` + ## [8.0] - 2024-07-01 ### Changed -- `pom.xml`, `deploy.yml`: tidied up following conversion to GitHub Actions +- `build.xml`, `deploy.yml`: tidied up following conversion to GitHub Actions - `pom.xml`: updated Kotlin version to 1.9.24 - `JSONInt`, `JSONLong`, `JSONDecimal`: modify for deprecation in Kotlin 1.9.x (These would not normally be breaking changes, but the major version should have been updated for version 7.4 because diff --git a/README.md b/README.md index a7a23a9..eccba60 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,10 @@ The exception also includes a property `key` (of type `Any?`) which is used to p the error, for example a [`JSONPointer`](https://github.com/pwall567/kjson-pointer) or a property name. When the key is provided, it will be appended to the message, as "`, at {key}`". +Starting from version 8.1 of this library, `JSONException` has been extracted to a separate library – +[`kjson-exception`](https://github.com/pwall567/kjson-exception) – so that it may be included in other projects +independent from this library + ### `JSONTypeException` A common error case arises when a `JSONValue` is found to be of the wrong type, for example, when a `JSONArray` is @@ -653,25 +657,25 @@ The diagram was produced by [Dia](https://wiki.gnome.org/Apps/Dia/); the diagram ## Dependency Specification -The latest version of the library is 8.0, and it may be obtained from the Maven Central repository. +The latest version of the library is 8.1, and it may be obtained from the Maven Central repository. ### Maven ```xml io.kjson kjson-core - 8.0 + 8.1 ``` ### Gradle ```groovy - implementation "io.kjson:kjson-core:8.0" + implementation "io.kjson:kjson-core:8.1" ``` ### Gradle (kts) ```kotlin - implementation("io.kjson:kjson-core:8.0") + implementation("io.kjson:kjson-core:8.1") ``` Peter Wall -2024-07-01 +2024-07-03 diff --git a/pom.xml b/pom.xml index 89e520b..060e41a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 kjson-core - 8.0 + 8.1 JSON Kotlin core functionality JSON Kotlin core functionality jar @@ -60,6 +60,11 @@ + + io.kjson + kjson-exception + 1.1 + net.pwall.json json-functions diff --git a/src/main/kotlin/io/kjson/JSONException.kt b/src/main/kotlin/io/kjson/JSONException.kt deleted file mode 100644 index 3dd2fd6..0000000 --- a/src/main/kotlin/io/kjson/JSONException.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * @(#) JSONException.kt - * - * kjson-core JSON Kotlin core functionality - * Copyright (c) 2021, 2023, 2024 Peter Wall - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package io.kjson - -/** - * A base exception class for JSON errors. - * - * @author Peter Wall - */ -open class JSONException(message: String, key: Any? = null): RuntimeException(extendMessage(message, key)) { - - override val message: String - get() = super.message!! // message will always be non-null - - companion object { - - fun extendMessage(message: String, key: Any?): String { - key?.toString()?.let { - if (it.isNotEmpty()) - return "$message, at $it" - } - return message - } - - } - -} diff --git a/src/main/kotlin/io/kjson/JSONTypeException.kt b/src/main/kotlin/io/kjson/JSONTypeException.kt index d7a6f9b..768a6d3 100644 --- a/src/main/kotlin/io/kjson/JSONTypeException.kt +++ b/src/main/kotlin/io/kjson/JSONTypeException.kt @@ -37,5 +37,5 @@ class JSONTypeException( val nodeName: String = "Node", val target: String, val value: JSONValue?, - val key: Any? = null, + key: Any? = null, ) : JSONException("$nodeName not correct type ($target), was ${value.displayValue()}", key) diff --git a/src/main/kotlin/io/kjson/parser/ParseException.kt b/src/main/kotlin/io/kjson/parser/ParseException.kt index 0017f3c..da104ba 100644 --- a/src/main/kotlin/io/kjson/parser/ParseException.kt +++ b/src/main/kotlin/io/kjson/parser/ParseException.kt @@ -2,7 +2,7 @@ * @(#) ParseException.kt * * kjson-core JSON Kotlin core functionality - * Copyright (c) 2021 Peter Wall + * Copyright (c) 2021, 2024 Peter Wall * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,4 +33,12 @@ import io.kjson.parser.ParserConstants.rootPointer * * @author Peter Wall */ -class ParseException(val text: String, val pointer: String = rootPointer) : JSONException(text, pointer) +class ParseException( + text: String, + override val key: String = rootPointer, +) : JSONException(text, key) { + + val pointer: String + get() = key + +} diff --git a/src/main/kotlin/io/kjson/parser/ParserConstants.kt b/src/main/kotlin/io/kjson/parser/ParserConstants.kt index 9c75533..986833f 100644 --- a/src/main/kotlin/io/kjson/parser/ParserConstants.kt +++ b/src/main/kotlin/io/kjson/parser/ParserConstants.kt @@ -35,6 +35,7 @@ import io.kjson.util.LookupSet @Suppress("unused") object ParserConstants { + @Suppress("ConstPropertyName") const val rootPointer = "" const val BOM = '\uFEFF' const val MAX_INTEGER_DIGITS_LENGTH = 10