Skip to content

Commit

Permalink
fix json serializer nil exception (#79)
Browse files Browse the repository at this point in the history
if hash was missing @context key the json serializer throwed a nil exception
  • Loading branch information
RaimiSol authored and syphax-bouazzouni committed Sep 12, 2023
1 parent 41e674f commit bf682ec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ group :development do
end

# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'master'
gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master'
80 changes: 43 additions & 37 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 3d5bbe1db4a6aca2ff621ccfcdb85a32dbe9704e
branch: development
revision: bd7154217438c3b9160e0e9b495c7c718b55fbf8
branch: master
specs:
goo (0.0.2)
addressable (~> 2.8)
Expand Down Expand Up @@ -32,27 +32,28 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.8.1)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ansi (1.5.0)
ast (2.4.2)
bcrypt (3.1.18)
base64 (0.1.1)
bcrypt (3.1.19)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.1.10)
connection_pool (2.3.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
cube-ruby (0.0.3)
daemons (1.4.1)
date (3.3.2)
date (3.3.3)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
email_spec (2.2.1)
email_spec (2.2.2)
htmlentities (~> 4.3.3)
launchy (~> 2.1)
mail (~> 2.7)
eventmachine (1.2.7)
faraday (1.10.2)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down Expand Up @@ -85,32 +86,33 @@ GEM
concurrent-ruby (~> 1.0)
json (2.6.3)
json_pure (2.6.3)
launchy (2.5.0)
addressable (~> 2.7)
language_server-protocol (3.17.0.3)
launchy (2.5.2)
addressable (~> 2.8)
libxml-ruby (2.9.0)
logger (1.5.3)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.8.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
method_source (1.0.0)
mime-types (3.4.1)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
mime-types-data (3.2023.0808)
mini_mime (1.1.5)
minitest (4.7.5)
minitest-reporters (0.14.24)
ansi
builder
minitest (>= 2.12, < 5.0)
powerbar
multi_json (1.15.0)
multipart-post (2.2.3)
multipart-post (2.3.0)
net-http-persistent (2.9.4)
net-imap (0.3.2)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -123,53 +125,57 @@ GEM
oj (2.18.5)
omni_logger (0.1.4)
logger
parallel (1.22.1)
parser (3.1.3.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
pony (1.13.1)
mail (>= 2.0)
powerbar (2.0.1)
hashie (>= 1.1.0)
pry (0.14.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.1)
public_suffix (5.0.3)
racc (1.7.1)
rack (1.6.13)
rack-test (0.8.3)
rack (>= 1.0, < 3)
rainbow (3.1.1)
rake (10.5.0)
rdf (1.0.8)
addressable (>= 2.2)
redis (5.0.5)
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.11.2)
redis-client (0.17.0)
connection_pool
regexp_parser (2.6.1)
regexp_parser (2.8.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rexml (3.2.6)
rsolr (1.1.2)
builder (>= 2.1.2)
rubocop (1.40.0)
rubocop (1.56.3)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.23.0, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.24.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (1.3.0)
simplecov (0.21.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
Expand All @@ -181,17 +187,17 @@ GEM
systemu (2.6.5)
test-unit-minitest (0.9.1)
minitest (~> 4.7)
thin (1.8.1)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
timeout (0.3.1)
tzinfo (0.3.61)
timeout (0.4.0)
tzinfo (0.3.62)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.3.0)
unicode-display_width (2.4.2)
uuid (2.3.9)
macaddr (~> 1.0)

Expand Down
9 changes: 7 additions & 2 deletions lib/ontologies_linked_data/serializers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.serialize(obj, options = {})
hash["links"].merge!(generate_links_context(hashed_obj)) if generate_context?(options)
end
end

# Generate context
if current_cls.ancestors.include?(Goo::Base::Resource) && !current_cls.embedded?
if generate_context?(options)
Expand All @@ -40,7 +40,12 @@ def self.serialize(obj, options = {})
context = {"@context" => context_hash}
hash.merge!(context)
end
hash['@context']['@language'] = options[:lang]

if hash.key?('@context')
hash['@context']['@language'] = options[:lang]
else
hash['@context'] = {'@language' => options[:lang]}
end
end
MultiJson.dump(hash)
end
Expand Down

0 comments on commit bf682ec

Please sign in to comment.