Skip to content

Commit 140cdfe

Browse files
Merge pull request #634 from Contextable/fix/issue631
chore: vendor json patch implementation for kotlin 2
2 parents 190479c + 7133479 commit 140cdfe

30 files changed

+2331
-14
lines changed

sdks/community/kotlin/library/client/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ kotlin {
7676
implementation(libs.kotlinx.serialization.json)
7777
implementation(libs.kotlinx.datetime)
7878

79-
// Json Patching
80-
implementation(libs.kotlin.json.patch)
81-
8279
// HTTP client dependencies - core only (no engine)
8380
implementation(libs.ktor.client.core)
8481
implementation(libs.ktor.client.content.negotiation)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2016 flipkart.com zjsonpatch.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.agui.client.jsonpatch
18+
import kotlinx.serialization.json.*
19+
20+
class ApplyProcessor(private val target: JsonElement) : JsonPatchApplyProcessor(target.deepCopy()) {
21+
fun result(): JsonElement = targetSource
22+
}
23+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2016 flipkart.com zjsonpatch.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.agui.client.jsonpatch
18+
19+
/**
20+
* Created by tomerga on 04/09/2016.
21+
*/
22+
enum class CompatibilityFlags {
23+
MISSING_VALUES_AS_NULLS;
24+
25+
26+
companion object {
27+
fun defaults(): Set<CompatibilityFlags> {
28+
return setOf(CompatibilityFlags.MISSING_VALUES_AS_NULLS)
29+
}
30+
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.agui.client.jsonpatch
2+
3+
open class Constants {
4+
open val OP = "op"
5+
open val VALUE = "value"
6+
open val PATH = "path"
7+
open val FROM = "from"
8+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2016 flipkart.com zjsonpatch.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.agui.client.jsonpatch
18+
19+
import kotlinx.serialization.json.JsonElement
20+
import kotlinx.serialization.json.JsonNull
21+
import kotlin.jvm.JvmStatic
22+
23+
internal class Diff {
24+
val operation: Int
25+
val path: MutableList<Any>
26+
val value: JsonElement
27+
val toPath: List<Any> //only to be used in move operation
28+
29+
constructor(operation: Int, path: List<Any>, value: JsonElement) {
30+
this.operation = operation
31+
this.path = path.toMutableList()
32+
this.toPath= listOf()
33+
this.value = value
34+
}
35+
36+
constructor(operation: Int, fromPath: List<Any>, toPath: List<Any>) {
37+
this.operation = operation
38+
this.path = fromPath.toMutableList()
39+
this.toPath = toPath
40+
this.value = JsonNull
41+
}
42+
43+
companion object {
44+
45+
@JvmStatic
46+
fun generateDiff(replace: Int, path: List<Any>, target: JsonElement): Diff {
47+
return Diff(replace, path, target)
48+
}
49+
}
50+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2016 flipkart.com zjsonpatch.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.agui.client.jsonpatch
18+
19+
/**
20+
* User: holograph
21+
* Date: 03/08/16
22+
*/
23+
class InvalidJsonPatchException : JsonPatchApplicationException {
24+
constructor(message: String) : super(message) {}
25+
26+
constructor(message: String, cause: Throwable) : super(message, cause) {}
27+
28+
constructor(cause: Throwable) : super(cause) {}
29+
}

0 commit comments

Comments
 (0)