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

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

Comments

Projects
None yet
3 participants
@landal79

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

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Oct 27, 2016

Owner

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
.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@landal79

landal79 Oct 28, 2016

Thanks for the answer

Thanks for the answer

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Oct 28, 2016

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@grahamegrieve

grahamegrieve Oct 28, 2016

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Dec 10, 2016

Owner

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.

Owner

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