question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support path expressions in object binding @Json annotations

See original GitHub issue

Would be nice to be able to do say: @Json(path="level1.level2.level3") for times when JSON has nested objects but you only want to construct a flat object from it.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kairuyancommented, Nov 26, 2018

Hi. I have a question similar to the one above. for times when JSON has nested objects but you only want to construct a flat object from it. However, the last one is array. Add to The name of the json key is object. This is a reserved word in kotlin, so I gave it a name to replace it with another word, but it does not work.

@Json(path = “$.data.object.images[1]”) var image : String @Json(path = “$.data.object.images”) var images : JsonArray<String> @Json(name = “object”) var obj : JsonObject

Couldn't find path "$.data.object.images[0]" specified on field "image"

but @Json(paht = “$.data.object.name”) var name : String get name value : tester

1reaction
cbeustcommented, Jan 22, 2018

I have the following working with very little changes right now:

    data class WithPath(
        val id: Int,
        @Json(path = "$.person.name")
        val name: String
    )

    fun fieldWithPath() {
        val result = Klaxon()
            .parse<WithPath>(StringReader("""{
            "id": 2,
            "person": {
               "name": "John"
            }
        }"""))
        assertThat(result).isEqualTo(WithPath(2, "John"))
    }

Trying to think of potential corner cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Functions bindings expressions and patterns
Learn to create different Azure Functions binding expressions based on common patterns.
Read more >
More Jackson Annotations - Baeldung
The @JsonAppend annotation is used to add virtual properties to an object in addition to regular ones when that object is serialized. This...
Read more >
The JSON Binding API in a nutshell - IBM Developer
Most importantly, this API provides binding support between Java classes and JSON documents in an intuitive and easy manner. Even developers ...
Read more >
SQL/JSON Path Expressions - Oracle Help Center
SQL/JSON path expressions are matched by SQL/JSON functions and conditions against JSON data, to select portions of it. Path expressions can use wildcards...
Read more >
POJO Data Binding Interface (Java Application Developer's ...
Use PojoRepository.write to insert or update POJOs in a MarkLogic database. Your POJO class definition must include at least an @Id annotation and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found