Comments (6)
@antonivanopoulos we are using oj in the application where I was running into this issue. That is probably the cause for me.
from fhir_client.
It doesn't seem to like the JSON.pretty_generate(to_hash, opts) if I'm reading it correctly
require 'json'
module FHIR
module Json
#
# This module includes methods to serialize or deserialize FHIR resources to and from JSON.
#
def to_json(opts = nil)
JSON.pretty_generate(to_hash, opts)
end
def self.from_json(json)
hash = JSON.parse(json)
resource = nil
begin
resource_type = hash['resourceType']
klass = Module.const_get("FHIR::#{resource_type}")
resource = klass.new(hash)
rescue => e
FHIR.logger.error("Failed to deserialize JSON:\n#{e.backtrace}")
FHIR.logger.debug("JSON:\n#{json}")
resource = nil
end
resource
end
end
end
from fhir_client.
I am having the same issue. We are running ruby version 3.0.1, could that be a potential cause of this?
If I make a call to to_json
and pass an empty hash as an argument it seems to serialize correctly.
from fhir_client.
@trazaq, for now I was able to work around this by overriding the to_json
method to pass an empty hash.
I am using the gem in a rails app so I was able to create a file at config/initializers/overrides.rb
with the following contents.
module FHIR
module Json
def to_json(opts = {})
super
end
end
end
That has me going for now, but I am not sure what the implications of doing something like that might be for your code, so YMMV.
from fhir_client.
I appreciate the authors of this gem! It does indeed come in handy!
Ah! That's one way of going about it!
Anyway,
For me, I couldn't really wait around for an answer because I'm on a timeline so I decided to use FHIR models only of this gem. (I do realize there's a separate gem for models only, too)
I'm not using this gem's internal HTTP client.
I construct the models and use HTTParty to do the actual sending/receiving of data as my HTTP client.
Works well so far. Just have to remember to convert your model to a hash, then to json in my case before sending it to the receiving system.
from fhir_client.
@trazaq @tugboat Do either of you use Oj? I ran into the same issue and it was due to our current use of Oj's optimize_rails
method that redefines the JSON module, introducing the behaviour you're seeing on #pretty_generate
. I found that if just using the json
gem, it doesn't behave that way.
from fhir_client.
Related Issues (20)
- Can't run rake fhir:console HOT 3
- bundle exec rake fhir:console (error) HOT 11
- Unable to obtain Access Token from Authorization Code HOT 3
- unable to get AllergyIntolerence from FHIR for a patient HOT 1
- fhir::count task fails on R4 server HOT 1
- Is there any option to get patient information from NHS server HOT 2
- Can't modify frozen String
- Using with SMART on FHIR Integration HOT 3
- Confusing conditions in `parse_reply` method HOT 2
- Gem::InstallError: zeitwerk requires Ruby version >= 2.4.4.
- Client response body conversion to JSON
- SMART on FHIR
- OAuth2 access token is not passed to `client.client_credentials.get_token`
- oauth2 gem used by fhir_client is EOL
- set_tls_auth
- Can this gem instantiate a new Patient object from json HOT 3
- Developers Seeking Advise for Working with FHIR HOT 7
- Parser warning during search HOT 1
- Issues sifting through response from FHIR HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fhir_client.