Generally I wonder, I am not the first one who met json<->moose mapping problem. There should be some existing solutions, and I should look at them and choose one that fits me better.
But if I imagine some ideal solution for me it would be something like that:
{
"body_raw" : "This is <b>Entry 1</b>",
"url" : "http://nataraj.nataraj.hack.dreamwidth.net/459.html",
"datetime" : "2022-08-20 16:36:00",
"entry_id" : 459,
"subject_html" : "Entry 1",
"poster" : {
"display_name" : "nataraj",
"username" : "nataraj"
},
"icon" : {
"url" : "http://www.nataraj.hack.dreamwidth.net/userpic/1/3",
"comment" : "4",
"picid" : 1,
"keywords" : [
"3"
],
"username" : "nataraj"
},
"subject_raw" : "Entry 1",
"body_html" : "This is <b>Entry 1</b>"
}
package Moose::MyCoolRestObject;
use MooseX::JSONBase;
has_json_string url => ();
has_json_datetime datetime => ();
has_json_int id => ();
has_json_object icon => ("Moose::MyCoolRestObject::Icon");
And then use it like this:
my $obj = Moose::MyCoolRestObject->new($json);
print $obj->icon->username;
I guess I can write something like this, if nothing similar does not exist...