use proper JSON encoding/decoding

This commit is contained in:
Graham Knop 2009-02-10 21:41:36 +00:00
parent 7023683b48
commit bf9bd2f0d2
18 changed files with 54 additions and 54 deletions

View file

@ -902,7 +902,7 @@ sub www_getAttributes {
my $jsonOutput;
$jsonOutput->{ResultSet} = {Result=>\@results};
return JSON->new->utf8->encode($jsonOutput);
return JSON->new->encode($jsonOutput);
}
#-------------------------------------------------------------------

View file

@ -561,7 +561,7 @@ sub getRichEditor {
while (my ($plugin, $path) = each %loadPlugins) {
$out .= "tinymce.PluginManager.load('$plugin', '$path');\n";
}
$out .= "\ttinyMCE.init(" . JSON->new->utf8->pretty->encode(\%config) . " )\n"
$out .= "\ttinyMCE.init(" . JSON->new->pretty->encode(\%config) . " )\n"
. "</script>";
}

View file

@ -377,7 +377,7 @@ sub view {
. WebGUI::Form::hidden($session,
{
name => "callback",
value => JSON->new->utf8->encode({ url => $self->getUrl})
value => JSON->new->encode({ url => $self->getUrl})
})
. WebGUI::Form::submit($session, {value => $i18n->get("populate from address book")})
. WebGUI::Form::formFooter($session)

View file

@ -17,7 +17,7 @@ package WebGUI::Asset::Sku::EMSTicket;
use strict;
use base 'WebGUI::Asset::Sku';
use Tie::IxHash;
use JSON;
use JSON ();
use WebGUI::Utility;
=head1 NAME
@ -293,7 +293,7 @@ If specified, returns a single value for the key specified.
sub getEventMetaData {
my $self = shift;
my $key = shift;
my $metadata = JSON->new->utf8->decode($self->get("eventMetaData") || '{}');
my $metadata = JSON->new->decode($self->get("eventMetaData") || '{}');
if (defined $key) {
return $metadata->{$key};
}
@ -438,7 +438,7 @@ sub processPropertiesFromFormPost {
my $date = WebGUI::DateTime->new($self->session, time())->toDatabase;
my $startDate = $form->process('startDate', "dateTime", $date,
{ defaultValue => $date, timeZone => $self->getParent->get("timezone")});
$self->update({eventMetaData => JSON->new->utf8->encode(\%metadata), startDate => $startDate});
$self->update({eventMetaData => JSON->new->encode(\%metadata), startDate => $startDate});
}
#-------------------------------------------------------------------
@ -470,7 +470,7 @@ A hash reference containing all the metadata properties to set.
sub setEventMetaData {
my $self = shift;
my $properties = shift;
$self->update({eventMetaData => JSON->new->utf8->encode($properties)});
$self->update({eventMetaData => JSON->new->encode($properties)});
}
#-------------------------------------------------------------------

View file

@ -573,7 +573,7 @@ sub www_editBadgeGroup {
my ($form, $db) = $self->session->quick(qw(form db));
my $f = WebGUI::HTMLForm->new($self->session, action=>$self->getUrl);
my $badgeGroup = $db->getRow("EMSBadgeGroup","badgeGroupId",$form->get('badgeGroupId'));
$badgeGroup->{badgeList} = ($badgeGroup->{badgeList} ne "") ? JSON::decode_json($badgeGroup->{badgeList}) : [];
$badgeGroup->{badgeList} = ($badgeGroup->{badgeList} ne "") ? JSON::from_json($badgeGroup->{badgeList}) : [];
my $i18n = WebGUI::International->new($self->session, "Asset_EventManagementSystem");
$f->hidden(name=>'func', value=>'editBadgeGroupSave');
$f->hidden(name=>'badgeGroupId', value=>$form->get('badgeGroupId'));
@ -842,7 +842,7 @@ sub www_getBadgesAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------
@ -974,7 +974,7 @@ sub www_getRegistrantAsJson {
$badgeInfo->{ribbons} = \@ribbons;
# build json datasource
return JSON->new->utf8->encode($badgeInfo);
return JSON->new->encode($badgeInfo);
}
#-------------------------------------------------------------------
@ -1038,7 +1038,7 @@ sub www_getRegistrantsAsJson {
# build json datasource
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1073,7 +1073,7 @@ sub www_getRibbonsAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1184,7 +1184,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
my $description = $ticket->get('description');
my $data = $ticket->get('eventMetaData');
$data = '{}' if ($data eq "");
my $meta = JSON->new->utf8->decode($data);
my $meta = JSON->new->decode($data);
foreach my $field (@{$self->getEventMetaFields}) {
my $label = $field->{label};
if ($field->{visible} && $meta->{$label} ne "") {
@ -1228,7 +1228,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1263,7 +1263,7 @@ sub www_getTokensAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------

View file

@ -987,7 +987,7 @@ assetData.revisionDate
my $jsonOutput;
$jsonOutput->{ResultSet} = {Result=>\@results};
my $encodedOutput = JSON->new->utf8->encode($jsonOutput);
my $encodedOutput = JSON->new->encode($jsonOutput);
return $encodedOutput;
}
@ -1090,7 +1090,7 @@ sub www_getCompareListData {
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($jsonOutput);
return JSON->new->encode($jsonOutput);
}
#-------------------------------------------------------------------

View file

@ -1517,7 +1517,7 @@ sub www_deleteThingDataViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -1528,11 +1528,11 @@ sub www_deleteThingDataViaAjax {
$self->deleteThingData($thingId,$thingDataId);
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode({message => "Data with thingDataId $thingDataId was deleted."});
return JSON->new->encode({message => "Data with thingDataId $thingDataId was deleted."});
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you specified can not be found."});
return JSON->new->encode({message => "The thingId you specified can not be found."});
}
}
@ -2455,7 +2455,7 @@ sub www_editThingDataSaveViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -2467,19 +2467,19 @@ sub www_editThingDataSaveViaAjax {
if($thingDataId eq 'new' && $self->hasEnteredMaxPerUser($thingId)){
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => $i18n->get("has entered max per user message")});
return JSON->new->encode({message => $i18n->get("has entered max per user message")});
}
my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId);
if ($errors){
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode($errors);
return JSON->new->encode($errors);
}
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -2568,7 +2568,7 @@ sub www_getThingViaAjax {
unless ($thingId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't return thing properties without a thingId."});
return JSON->new->encode({message => "Can't return thing properties without a thingId."});
}
my $thingProperties = $self->getThing($thingId);
@ -2586,11 +2586,11 @@ sub www_getThingViaAjax {
$thingProperties->{field_loop} = \@field_loop;
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($thingProperties);
return JSON->new->encode($thingProperties);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -2620,11 +2620,11 @@ sub www_getThingsViaAjax {
}
}
if (scalar @visibleThings > 0){
return JSON->new->utf8->encode(\@visibleThings);
return JSON->new->encode(\@visibleThings);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "No visible Things were found in this Thingy."});
return JSON->new->encode({message => "No visible Things were found in this Thingy."});
}
}
@ -2982,7 +2982,7 @@ sub www_searchViaAjax {
unless ($thingId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't perform search without a thingId."});
return JSON->new->encode({message => "Can't perform search without a thingId."});
}
if ($thingProperties->{thingId}){
@ -2993,11 +2993,11 @@ sub www_searchViaAjax {
my $var = $self->getSearchTemplateVars($thingId,$thingProperties);
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($var);
return JSON->new->encode($var);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -3393,7 +3393,7 @@ sub www_viewThingDataViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -3404,16 +3404,16 @@ sub www_viewThingDataViaAjax {
my $output = $self->getViewThingVars($thingId,$thingDataId);
if ($output){
return JSON->new->utf8->encode($output);
return JSON->new->encode($output);
}
else{
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingDataId you requested can not be found."});
return JSON->new->encode({message => "The thingDataId you requested can not be found."});
}
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}

View file

@ -97,7 +97,7 @@ sub www_spectreGetSiteData {
}
$siteData{cron} = \@schedules;
}
return JSON::encode_json(\%siteData);
return JSON::to_json(\%siteData);
}
#-------------------------------------------------------------------

View file

@ -200,7 +200,7 @@ sub www_spellCheck {
# work around TinyMCE JSON encoding bug
$data =~ s/([^\\](?:\\\\)*)\\'/$1'/g;
my $params = JSON->new->utf8->decode($data);
my $params = JSON->new->decode($data);
my $result;
# dispatch to different subs based on the 'method' in the JSON data

View file

@ -502,7 +502,7 @@ sub www_view {
my $form = $session->form;
my $callback = $form->get('callback');
$callback =~ s/'/"/g;
$callback = JSON->new->utf8->decode($callback);
$callback = JSON->new->decode($callback);
my $callbackForm = '';
foreach my $param (@{$callback->{params}}) {
$callbackForm .= WebGUI::Form::hidden($session, {name=>$param->{name}, value=>$param->{value}});

View file

@ -126,7 +126,7 @@ sub get {
return {};
}
else {
return JSON->new->utf8->decode($properties{id $self}{$name});
return JSON->new->decode($properties{id $self}{$name});
}
}
return $properties{id $self}{$name};
@ -306,7 +306,7 @@ sub update {
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
}
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
$properties{$id}{options} = JSON->new->utf8->encode($newProperties->{options});
$properties{$id}{options} = JSON->new->encode($newProperties->{options});
}
$self->cart->session->db->setRow("cartItem","itemId",$properties{$id});
}

View file

@ -711,7 +711,7 @@ sub www_getTransactionsAsJson {
$results{'sort'} = undef;
$results{'dir'} = "desc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------

View file

@ -98,7 +98,7 @@ sub get {
return {};
}
else {
return JSON->new->utf8->decode($properties{id $self}{$name});
return JSON->new->decode($properties{id $self}{$name});
}
}
return $properties{id $self}{$name};
@ -294,7 +294,7 @@ sub update {
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
}
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
$properties{$id}{options} = JSON->new->utf8->encode($newProperties->{options});
$properties{$id}{options} = JSON->new->encode($newProperties->{options});
}
$properties{$id}{lastUpdated} = WebGUI::DateTime->new($self->transaction->session,time())->toDatabase;
$self->transaction->session->db->setRow("transactionItem","itemId",$properties{$id});

View file

@ -117,7 +117,7 @@ sub get {
my $name = shift;
if ($name eq "parameters") {
if (exists $self->{_data}{parameters} && $self->{_data}{parameters} ne "") {
my $parameters = JSON::decode_json($self->{_data}{$name});
my $parameters = JSON::from_json($self->{_data}{$name});
return $parameters->{parameters};
}
else {
@ -303,7 +303,7 @@ sub set {
$self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className};
$self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
if (exists $properties->{parameters}) {
$self->{_data}{parameters} = JSON->new->utf8->pretty->encode({parameters => $properties->{parameters}});
$self->{_data}{parameters} = JSON->new->pretty->encode({parameters => $properties->{parameters}});
}
$self->{_data}{enabled} = 0 unless ($self->{_data}{workflowId});
my $spectre = WebGUI::Workflow::Spectre->new($self->session);

View file

@ -66,7 +66,7 @@ sub create {
my ($isSingleton) = $session->db->quickArray("select count(*) from Workflow where workflowId=? and mode='singleton'",$placeHolders);
my $sql = "select count(*) from WorkflowInstance where workflowId=?";
if (exists $properties->{parameters}) {
push @{ $placeHolders }, JSON->new->utf8->canonical->encode({parameters => $properties->{parameters}});
push @{ $placeHolders }, JSON->new->canonical->encode({parameters => $properties->{parameters}});
$sql .= ' and parameters=?';
}
else {
@ -466,7 +466,7 @@ sub set {
$self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className};
$self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
if (exists $properties->{parameters}) {
$self->{_data}{parameters} = JSON->new->utf8->canonical->encode({parameters => $properties->{parameters}});
$self->{_data}{parameters} = JSON->new->canonical->encode({parameters => $properties->{parameters}});
}
$self->{_data}{currentActivityId} = (exists $properties->{currentActivityId}) ? $properties->{currentActivityId} : $self->{_data}{currentActivityId};
$self->session->db->setRow("WorkflowInstance","instanceId",$self->{_data});

View file

@ -56,7 +56,7 @@ ok($session->id->valid($vid), 'a valid id was generated for the new collateral e
my $json;
$json = $product->get('variantsJSON');
my $jsonData = decode_json($json);
my $jsonData = JSON::from_json($json);
cmp_deeply(
$jsonData,
[ {a => 'aye', b => 'bee', vid => $vid } ],

View file

@ -107,7 +107,7 @@ isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing');
$session->user({userId => 3});
my $json = $matrix->www_getCompareFormData('score');
my $compareFormData = JSON->new->utf8->decode($json);
my $compareFormData = JSON->new->decode($json);
cmp_deeply(
$compareFormData,

View file

@ -86,7 +86,7 @@ is($thingy->get('defaultThingId'),$thingId,"The Thingy assets defaultThingId was
$session->user({userId => 3});
my $json = $thingy->www_getThingViaAjax($thingId);
my $dataFromJSON = JSON->new->utf8->decode($json);
my $dataFromJSON = JSON->new->decode($json);
cmp_deeply(
$dataFromJSON,
@ -127,7 +127,7 @@ cmp_deeply(
# the newly created thing.
$json = $thingy->www_getThingsViaAjax();
$dataFromJSON = JSON->new->utf8->decode($json);
$dataFromJSON = JSON->new->decode($json);
cmp_deeply(
$dataFromJSON,
@ -220,7 +220,7 @@ cmp_deeply(
);
$json = $thingy->www_viewThingDataViaAjax($thingId,$newThingDataId);
$dataFromJSON = JSON->new->utf8->decode($json);
$dataFromJSON = JSON->new->decode($json);
cmp_deeply(
$dataFromJSON,
@ -268,7 +268,7 @@ $thingy->deleteThingData($thingId,$newThingDataId);
is($thingy->getViewThingVars($thingId,$newThingDataId),undef,'Thing data was succesfully deleted, getViewThingVars returns undef.');
$json = $thingy->www_viewThingDataViaAjax($thingId,$newThingDataId);
$dataFromJSON = JSON->new->utf8->decode($json);
$dataFromJSON = JSON->new->decode($json);
cmp_deeply(
$dataFromJSON,