Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ca.uhn.fhir.parser.DataFormatException with empty string in json #480

Closed
landal79 opened this issue Oct 27, 2016 · 5 comments
Closed

Comments

@landal79
Copy link

@landal79 landal79 commented Oct 27, 2016

Hi,

I'm using the following hapi version:

<dependency>
    <groupId>ca.uhn.hapi.fhir</groupId>
    <artifactId>hapi-fhir-structures-dstu2</artifactId>
    <version>2.0</version>
</dependency>

We have developed a javascript frontend for the resource Questionnaireand QuestionnaireResponse.
The frontend renders a form to create the QuestionnaireResponse data, when the user doesn't fill the boolean and integer fields we have the following json with empty responses:

"answer" : [{
            "valueInteger" : ""
        }
    ]

or

"answer" : [{
            "valueBoolean" : ""
        }
    ]

When we parse the reponse server side with:
FhirContext.forDstu2()..newJsonParser().parse()

we got:
ca.uhn.fhir.parser.DataFormatException: java.lang.NumberFormatException: For input string: ""

is this the desired behaviour?
We would like to get empty or null value in this case from the parser,
is there a way to workaround this behavior?

Thanks in advance
Alex

@jamesagnew
Copy link
Owner

@jamesagnew jamesagnew commented Oct 27, 2016

FYI according to FHIR's rules this isn't valid. Per the spec
https://www.hl7.org/fhir/formats.html, "This value attribute/property can
never be empty. Either it is absent, or it is present with at least one
character of non-whitespace content"

I think HAPI should be more forgiving so this bug report probably makes
sense to keep open, but FYI you would need to come up with an alternative
if you want to be fully conformant.

On Thu, Oct 27, 2016 at 11:15 AM, Landini Alex notifications@github.com
wrote:

Hi,

I'm using the following hapi version:

ca.uhn.hapi.fhir hapi-fhir-structures-dstu2 2.0

We have developed a javascript frontend for the resource Questionnaireand
QuestionnaireResponse.
The frontend renders a form to create the QuestionnaireResponse data, when
the user doesn't fill the boolean and integer fields we have the following
json with empty responses:

"answer" : [{
"valueInteger" : ""
}
]

or

"answer" : [{
"valueBoolean" : ""
}
]

When we parse the reponse server side with:
FhirContext.forDstu2()..newJsonParser().parse()

we got:
ca.uhn.fhir.parser.DataFormatException: java.lang.NumberFormatException:
For input string: ""

is this the desired behaviour?
We would like to get empty or null value in this case from the parser,
is there a way to workaround this behavior?

Thanks in advance
Alex


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#480, or mute the thread
https://github.com/notifications/unsubscribe-auth/ADTfnQu9UFFWnXQrPariKLGDo4tdCcZkks5q4MATgaJpZM4KieVk
.

@landal79 landal79 closed this Oct 28, 2016
@landal79
Copy link
Author

@landal79 landal79 commented Oct 28, 2016

Thanks for the answer

@jamesagnew
Copy link
Owner

@jamesagnew jamesagnew commented Oct 28, 2016

Hey @landal79 - I'm actually gonna keep this bug open. I do think that even though technically sending that empty value isn't FHIR conformant, this should be a warning in HAPI and not an exception by default.

@jamesagnew jamesagnew reopened this Oct 28, 2016
@grahamegrieve
Copy link
Collaborator

@grahamegrieve grahamegrieve commented Oct 28, 2016

I think it should be an exception by default, and can be downgraded to a
warning - but the message should be more useful ;-)

Grahame

On Sat, Oct 29, 2016 at 1:01 AM, James Agnew notifications@github.com
wrote:

Hey @landal79 https://github.com/landal79 - I'm actually gonna keep
this bug open. I do think that even though technically though sending that
empty value isn't FHIR conformant, this should be a warning in HAPI and not
an exception by default.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#480 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFllFVjxneTwS9uxX-6h5jDxhMSI08v_ks5q4gAtgaJpZM4KieVk
.


http://www.healthintersections.com.au / grahame@healthintersections.com.au
/ +61 411 867 065

@jamesagnew
Copy link
Owner

@jamesagnew jamesagnew commented Dec 10, 2016

Alright, this has been corected by the fixes for #525 for #516. The parser now handles invalid field values with an exception (or HTTP 400 for the server) by default, but this behaviour can be modified by confguring the parserErrorHandler on the context or on the parser.

@jamesagnew jamesagnew closed this Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.