-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Serialization: DontEncodeElements use results in invalid resource #6304
Comments
Agree this is an issue - it would be hard to fix in a way that doesn't hurt performance though. Patches welcomed. |
I can try to make a pull request for that, but my understanding of the parser is pretty low. I probably won't be able to come with an optimized patch. About performance, what are the important use cases? I guess the performance of the parser without that option enabled is important because it most likely represents the huge majority of its usage. |
The main thing I'm worried about is that we're not running huge emptiness checks in cases where they aren't needed. So, e.g. if you've called This code would get complicated fast, and would need to be aware of extensions too I suppose - E.g. if you exclude One alternate approach that might conceivably work would be to rework JacksonWriter so that it buffered the output events and only flushed the buffer for a given block once it encountered actual meaningful contents in that block. This too could get complex fast though and would need to be very comprehensively unit tested and performance benchmarked to ensure no regressions occurred. |
Describe the bug
When using the DontEncodeElements feature of the parser, the serialized resource is invalid if an element contains a single value, and that was ignored by DontEncodeElements. The element is added without content, which is not allowed by the FHIR specification.
To Reproduce
The code
results in:
Expected behavior
The parser should ignore Patient.name, as the only value in name[0] is ignored. But the parser is only checking if the name list is empty, or if all values are empty (which it is not).
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
Additional context
It looks like it's missing a check here:
hapi-fhir/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
Lines 553 to 563 in fb93c3d
The EncodeContext contains the information about elements to ignore, but it's not checked at this point. It will only be checked when name[0] is serialized.
Same for the XML parser.
The text was updated successfully, but these errors were encountered: