<@U6P03BM0W> this is what I’m doing : ``` object J...
# vertx
f
@dave08 this is what I’m doing :
Copy code
object JsonObjectUtils{
     inline operator fun JsonObject.set(key: String, value: Any): Unit {
        this.put(key,value)
    }
    inline operator fun <T> JsonObject.get(key: String): T {
        return this.getValue(key) as T
    }
    fun  JsonObject.getFlow(): JsonObject {
        return this.getJsonObject("flow")
    }
    fun  JsonObject.getFlowNodeId(): String {
        return this.getFlow().get("nodeId")
    }
    fun  JsonObject.setFlowNodeId(nodeId:String) {
        this.getFlow().put("nodeId",nodeId)
    }
    fun  JsonObject.getFlowName(): String {
        return this.getFlow().get("name")
    }
    fun  JsonObject.setFlowName(nodeId:String) {
        this.getFlow().put("name",nodeId)
    }
}
d
@fstn How does this simplify your eventbus code?
f
instead of doing
Copy code
message.body().getJsonObject("flow").getValue("nodeId")
I can use
Copy code
message.body().getFlowNodeId()
That I want If to use a dynamic object for the event bus message
but with the ability to get known value like property
d
@fstn Personally, I use the JsonObject itself to provide the parameters for my services that are in the Business Logic Layer of my app. The code retreiving and setting values to/from the bus should only be in one place, and then be delegated to other layers of the app using data classes or function parameters. If you only use this Utils class in one place it might be a waste to maintain it, you might be better off converting incoming messages to data classes to be used in other layers of the app. I hope I understand you properly... 😉
f
mmm I’m not sure to understand, sorry 😞 my body can be :
Copy code
{ 
    “user” : 
    {   
        “firstName” : “MyFirstName”
    }
    “flow”:
    {
        “id”:“myId”,
        “name”:“myName”
    }
}
or
Copy code
{
    "user" :
    {
        "firstName" : "MyFirstName",
        "dynamicProperty": "myDynamicProperty"
    }
    "flow":
    {
    }
}
so to do that you declare a data object context with 2 properties user and flow that are JsonObject?
and you get it with for example context.user
d
No, it depends on what input your logic needs. You need to convert it in a form you can easily process
Json is too flexible and might introduce errors of unexpected non existant values or formats
f
so How do you do a class this a dynamic part?
d
Whereas if you box it into a data class, it'll give you an error as to exactly what is missing from what the logic is expecting
Dynamic is always converted to something to process -- code is not dynamic
It's always expecting something specific...
f
so the solution can Be to have class User (val firstName:String,val lastName:String,val dynamicPart:JsonObject{
d
Try to rethink if you really need the dynamic and if it needs processing by your code - if it is just passed along you could even keep it as a json string...
f
It’s really dynamic, the dynamic part is save inside a jsonB column
and it can be consume by others app
d
But does it need processing?
f
yes because it’s for a workflow, user can modify the json inside the workflow
sorry 😞
d
User using the UI, but does your code touch it or just save as is in the db? and retrieve for the user to see
If so, you could even use a
val flow: String
, if not, you might think to make it into some State Machine
Good luck!
f
thanks @dave08 💪