Hello! I want to create an webhook microservice th...
# server
t
Hello! I want to create an webhook microservice that basically receives events from Facebook Messenger. I have some doubts about common solutions when mapping these kind of request body. The documentation says this is the kind of request that will be sent:
Copy code
{
  "object":"page",
  "entry":[
    {
      "id":"<PAGE_ID>",
      "time":1458692752478,
      "messaging":[
        {
          "sender":{ "id":"<PSID>" },
          "recipient":{ "id":"<PAGE_ID>" },
          ... // <-- this
        }
      ]
    }
  ]
}
where
...
can be different events like
message
,
reaction
,
postback
and others. My doubt is at this part. How do you guys map those kind of JSON? The content of each property isn’t that much important for me since once it’s mapped I can send to the correct microservice the original JSON.
f
Yeah I had the same issue earlier this year when making a chatbot for messenger. I ended up just getting `JsonObject`s from Jackson and checking the fields manually, trying to map this to objects is... basically impossible (even the same event can have different fields sometimes)
r
I haven’t used Jackson in a while, but if memory serves you can actually go from raw -> JsonObjects -> check which model to use -> convert the JsonObject to the model type… I think Json Objects should have a function to that effect.
f
Yeah you can, it's just a PITA to make the 75 million different classes to map things into
t
Yeah... I ended going this way too 😂 Since I don’t need the entire object mapped into classes in my Kotlin system I’ll try to map only the base part so I can decide what to do after with the request