-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting JsonPointer? #69
Comments
We've got JsonPath and this is isomorphic. I have no preference but we should pick the winner! |
I've just tried to create a naive implementation of JsonPath in moshi using annotations but I think it is not possible right now. Just after I add an attribute to my annotation moshi stops matching the adapter. In casy anybody would be interested in pushing this further, here is my code: class JsonPathFactory : JsonAdapter.Factory {
override fun create(type: Type?, annotations: MutableSet<out Annotation>, moshi: Moshi): JsonAdapter<*>? {
val jsonPathAnnotation = annotations.firstOrNull { it.annotationClass == JsonPath::class }
if (jsonPathAnnotation != null) {
val path = Proxy.getInvocationHandler(jsonPathAnnotation).invoke(jsonPathAnnotation, JsonPath::class.java.declaredMethods.first { it.name == "path" }, arrayOf()) as String
return object : JsonAdapter<String>() {
@JsonPath()
override fun fromJson(reader: JsonReader): String? {
@Suppress("UNCHECKED_CAST")
val map = reader.readJsonValue() as Map<String, Any>
var currentNode = map
val pathSegments = path.split("/")
pathSegments.dropLast(1).forEach {
@Suppress("UNCHECKED_CAST")
currentNode = currentNode[it] as Map<String, Any>
}
return currentNode[pathSegments.last()] as String
}
override fun toJson(writer: JsonWriter?, @JsonPath value: String?) = Unit
}
}
return null
}
}
@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class JsonPath(val path: String = "") |
Hey, any progress on the implementation of the JsonPointer? |
No one is working on this currently.
…On Mon, Aug 19, 2019 at 9:51 AM Daniel Nogueira ***@***.***> wrote:
Hey, any progress on the implementation of the JsonPointer?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#69?email_source=notifications&email_token=AAAQIEMQXX6DUNHDDFPB2O3QFKQPVA5CNFSM4BNAD2Y2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4TAHSI#issuecomment-522585033>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAQIEKTLWCOX2QECRZSYADQFKQPVANCNFSM4BNAD2YQ>
.
|
https://tools.ietf.org/html/rfc6901
Any thoughts on support JsonPointer for self-referencing values in a JSON doc? JSR-367 is planning to support it.
The text was updated successfully, but these errors were encountered: