From a7b677c2782ca2111032842671be33ee149ce4f7 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 22 Aug 2014 13:00:35 -0400 Subject: [PATCH] Teach opensrf object registration how to strip certain object members Signed-off-by: Mike Rylander --- src/perl/lib/OpenSRF/Application.pm | 9 +++++++-- src/perl/lib/OpenSRF/Utils/JSON.pm | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/perl/lib/OpenSRF/Application.pm b/src/perl/lib/OpenSRF/Application.pm index d409957..023bb8d 100644 --- a/src/perl/lib/OpenSRF/Application.pm +++ b/src/perl/lib/OpenSRF/Application.pm @@ -437,7 +437,12 @@ sub register_method { ($args{object_hint} = $args{package}) =~ s/::/_/go; } - OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" ); + OpenSRF::Utils::JSON->register_class_hint( + strip => ['session'], + name => $app, + hint => $args{object_hint}, + type => "hash" + ); $_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app; @@ -559,7 +564,7 @@ sub method_lookup { $meth = $self->method_lookup($method,$proto,1); } - $meth->session($self->session) if $meth; # Pass the caller's session + $meth->session($self->session) if $meth && ref($self); # Pass the caller's session return $meth; } diff --git a/src/perl/lib/OpenSRF/Utils/JSON.pm b/src/perl/lib/OpenSRF/Utils/JSON.pm index 6411870..4efa3dc 100644 --- a/src/perl/lib/OpenSRF/Utils/JSON.pm +++ b/src/perl/lib/OpenSRF/Utils/JSON.pm @@ -212,7 +212,14 @@ sub perl2JSONObject { if(UNIVERSAL::isa($obj, 'HASH')) { $jsonobj = {}; - $jsonobj->{$_} = $pkg->perl2JSONObject($obj->{$_}) for (keys %$obj); + for my $k (keys %$obj) { + next if ( + $ref ne 'HASH' + and exists $_class_map{classes}{$ref}{strip} + and grep { $k eq $_ } @{$_class_map{classes}{$ref}{strip}} + ); + $jsonobj->{$k} = $pkg->perl2JSONObject($obj->{$k}); + } } elsif(UNIVERSAL::isa($obj, 'ARRAY')) { $jsonobj = []; $jsonobj->[$_] = $pkg->perl2JSONObject($obj->[$_]) for(0..scalar(@$obj) - 1); -- 2.11.0