Open mostfa-ayad opened 4 years ago
why there is no implementation code for item.toJson ()
?
@SchweinchenFuntik i edit the post now
it turns out you get invalid JSON, you need to watch how the server sends data.
If you do not use Spring in principle, then you can use ktor + kotlinx serialization/
@ruckustboom have the opportunity to help?
@SchweinchenFuntik
i usually using spring boot and write my own controllers and end points
but i try to use spring boot data rest it very sample and make my live easy
Spring Data REST is built on top of the Spring Data project and makes it easy to build hypermedia-driven REST web services that connect to Spring Data repositories – all using HAL as the driving hypermedia type. It takes away a lot of the manual work usually associated with such tasks and makes implementing basic CRUD functionality for web applications quite simple.
i hope i can solve this with tornadofx
I understand, but you need to make sure that the spring gives valid JSON. Based on the client code, I see no problems.
@SchweinchenFuntik
i test it with RESTED Client and it work the problem is with tornadofx
sorry again, does this come from a server or client?
{
"links" : [ {
"rel" : "self",
"href" : "http://localhost:8080/items"
}, {
"rel" : "profile",
"href" : "http://localhost:8080/profile/items"
} ],
"content" : [ {
"value" : [ ],
"rel" : null,
"collectionValue" : true,
"relTargetType" : "com.example.demo.Item"
} ]
}
from server
Well, this json does not match what the client is waiting for. On the client, do:
val items: List<Item> = // create elements
println(items.toJSON())
full example:
class TestView : View() {
override val root = vbox {
val item = Item().apply { id = 0; name = "test" }
println(item.toJSON())
println()
println(listOf(item).toJSON())
}
}
class Item : JsonModelAuto {
var id by property<Int>()
var name by property<String>()
}
console output:
{"id":0,"name":"test"}
[{"id":0,"name":"test"}]
@SchweinchenFuntik thank you but the problem is with get the JSON data from the server
this does not apply to tornadofx anymore, if you cannot change the server code, then it may be worth parsing manually.
also impossible to help without backend code
@SchweinchenFuntik you are right i will change the server code thanks alot for your help
Maybe, you should go with Traverson.
hello i try to start new project using tornadofx and springboot data rest spring boot data rest using a JSON format type application/hal+json like this
{ "_embedded" : { "items" : [ { "name" : "car", "_links" : { "self" : { "href" : "http://localhost:8080/items/1" }, "item" : { "href" : "http://localhost:8080/items/1" } } }, { "name" : "test", "_links" : { "self" : { "href" : "http://localhost:8080/items/2" }, "item" : { "href" : "http://localhost:8080/items/2" } } } ] }, "_links" : { "self" : { "href" : "http://localhost:8080/items" }, "profile" : { "href" : "http://localhost:8080/profile/items" } } } this format using two root _embedded and links and embedded has array of items that have my data my problem in read data insert work fine
the controller
i try this but can't get jsonArray api.get(path).consume().one().get("content")
i try to solve this problem with spring boot but i can't solve it and if i change the sprig boot JSON type to application/json this JSON is like this:
{ "links" : [ { "rel" : "self", "href" : "http://localhost:8080/items" }, { "rel" : "profile", "href" : "http://localhost:8080/profile/items" } ], "content" : [ { "value" : [ ], "rel" : null, "collectionValue" : true, "relTargetType" : "com.example.demo.Item" } ] }