in reply to Re: Framework for making Moose-compatible object from json
in thread Framework for making Moose-compatible object from json
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>" }
And then use it like this: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");
I guess I can write something like this, if nothing similar does not exist...my $obj = Moose::MyCoolRestObject->new($json); print $obj->icon->username;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Framework for making Moose-compatible object from json (serialization)
by LanX (Saint) on Aug 20, 2022 at 19:01 UTC | |
|
Re^3: Framework for making Moose-compatible object from json
by NERDVANA (Priest) on Aug 20, 2022 at 23:33 UTC |