
001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.parser; 021 022import ca.uhn.fhir.context.ConfigurationException; 023import ca.uhn.fhir.context.FhirContext; 024import ca.uhn.fhir.context.ParserOptions; 025import ca.uhn.fhir.i18n.Msg; 026import ca.uhn.fhir.model.api.IResource; 027import ca.uhn.fhir.rest.api.EncodingEnum; 028import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; 029import ca.uhn.fhir.util.CollectionUtil; 030import jakarta.annotation.Nonnull; 031import jakarta.annotation.Nullable; 032import org.hl7.fhir.instance.model.api.IAnyResource; 033import org.hl7.fhir.instance.model.api.IBase; 034import org.hl7.fhir.instance.model.api.IBaseResource; 035import org.hl7.fhir.instance.model.api.IIdType; 036 037import java.io.IOException; 038import java.io.InputStream; 039import java.io.Reader; 040import java.io.StringReader; 041import java.io.Writer; 042import java.util.Collection; 043import java.util.List; 044import java.util.Set; 045 046/** 047 * A parser, which can be used to convert between HAPI FHIR model/structure objects, and their respective String wire 048 * formats, in either XML or JSON. 049 * <p> 050 * Thread safety: <b>Parsers are not guaranteed to be thread safe</b>. Create a new parser instance for every thread or 051 * every message being parsed/encoded. 052 * </p> 053 */ 054public interface IParser { 055 056 /** 057 * Encodes a resource using the parser's given encoding format. 058 * 059 * @param theResource The resource to encode. Must not be null. 060 * @return A string representation of the encoding 061 * @throws DataFormatException If any invalid elements within the contents to be encoded prevent successful encoding. 062 */ 063 String encodeResourceToString(IBaseResource theResource) throws DataFormatException; 064 065 /** 066 * Encodes a resource using the parser's given encoding format. 067 * 068 * @param theResource The resource to encode. Must not be null. 069 * @param theWriter The writer to write to. 070 * @throws DataFormatException If any invalid elements within the contents to be encoded prevent successful encoding. 071 */ 072 void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException; 073 074 /** 075 * Encodes any FHIR element to a string. 076 * If a {@link IBaseResource resource object} is passed in, the resource will be encoded using standard FHIR 077 * encoding rules. If a {@link org.hl7.fhir.instance.model.api.IPrimitiveType primitive datatype} is passed in, 078 * the string value of the primitive type is encoded. Any extensions on the primitive type are not encoded. 079 * If any other object is passed in, a fragment is encoded. The format of the fragment depends on the encoding: 080 * <ul> 081 * <li><b>JSON</b>: The fragment is output as a simple JSON object, exactly as it would appear within an encoded resource.</li> 082 * <li><b>XML</b>: The fragment is output as an XML element as it would appear within an encoded resource, however it is wrapped in an element called <code><element></code> in order to avoid producing a document with multiple root tags.</li> 083 * <li><b>RDF/Turtle</b>: This mode is not supported and will throw an {@link ca.uhn.fhir.rest.server.exceptions.InternalErrorException}</li> 084 * </ul> 085 * 086 * @since 6.8.0 087 */ 088 String encodeToString(IBase theElement) throws DataFormatException; 089 090 /** 091 * Encodes any FHIR element to a writer. 092 * If a {@link IBaseResource resource object} is passed in, the resource will be encoded using standard FHIR 093 * encoding rules. If a {@link org.hl7.fhir.instance.model.api.IPrimitiveType primitive datatype} is passed in, 094 * the string value of the primitive type is encoded. Any extensions on the primitive type are not encoded. 095 * If any other object is passed in, a fragment is encoded. The format of the fragment depends on the encoding: 096 * <ul> 097 * <li><b>JSON</b>: The fragment is output as a simple JSON object, exactly as it would appear within an encoded resource.</li> 098 * <li><b>XML</b>: The fragment is output as an XML element as it would appear within an encoded resource, however it is wrapped in an element called <code><element></code> in order to avoid producing a document with multiple root tags.</li> 099 * <li><b>RDF/Turtle</b>: This mode is not supported and will throw an {@link ca.uhn.fhir.rest.server.exceptions.InternalErrorException}</li> 100 * </ul> 101 * 102 * @since 6.8.0 103 */ 104 void encodeToWriter(IBase theElement, Writer theWriter) throws DataFormatException, IOException; 105 106 /** 107 * If not set to null (as is the default) this ID will be used as the ID in any 108 * resources encoded by this parser 109 */ 110 IIdType getEncodeForceResourceId(); 111 112 /** 113 * When encoding, force this resource ID to be encoded as the resource ID 114 */ 115 @SuppressWarnings("UnusedReturnValue") 116 IParser setEncodeForceResourceId(IIdType theForceResourceId); 117 118 /** 119 * Which encoding does this parser instance produce? 120 */ 121 EncodingEnum getEncoding(); 122 123 /** 124 * Gets the preferred types, as set using {@link #setPreferTypes(List)} 125 * 126 * @return Returns the preferred types, or <code>null</code> 127 * @see #setPreferTypes(List) 128 */ 129 List<Class<? extends IBaseResource>> getPreferTypes(); 130 131 /** 132 * If set, when parsing resources the parser will try to use the given types when possible, in 133 * the order that they are provided (from highest to lowest priority). For example, if a custom 134 * type which declares to implement the Patient resource is passed in here, and the 135 * parser is parsing a Bundle containing a Patient resource, the parser will use the given 136 * custom type. 137 * <p> 138 * This feature is related to, but not the same as the 139 * {@link FhirContext#setDefaultTypeForProfile(String, Class)} feature. 140 * <code>setDefaultTypeForProfile</code> is used to specify a type to be used 141 * when a resource explicitly declares support for a given profile. This 142 * feature specifies a type to be used irrespective of the profile declaration 143 * in the metadata statement. 144 * </p> 145 * 146 * @param thePreferTypes The preferred types, or <code>null</code> 147 */ 148 void setPreferTypes(List<Class<? extends IBaseResource>> thePreferTypes); 149 150 /** 151 * Returns true if resource IDs should be omitted 152 * 153 * @see #setOmitResourceId(boolean) 154 * @since 1.1 155 */ 156 boolean isOmitResourceId(); 157 158 /** 159 * If set to <code>true</code> (default is <code>false</code>) the ID of any resources being encoded will not be 160 * included in the output. Note that this does not apply to contained resources, only to root resources. In other 161 * words, if this is set to <code>true</code>, contained resources will still have local IDs but the outer/containing 162 * ID will not have an ID. 163 * <p> 164 * If the resource being encoded is a Bundle or Parameters resource, this setting only applies to the 165 * outer resource being encoded, not any resources contained within. 166 * </p> 167 * 168 * @param theOmitResourceId Should resource IDs be omitted 169 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 170 * @since 1.1 171 */ 172 IParser setOmitResourceId(boolean theOmitResourceId); 173 174 /** 175 * If set to <code>true<code> (which is the default), resource references containing a version 176 * will have the version removed when the resource is encoded. This is generally good behaviour because 177 * in most situations, references from one resource to another should be to the resource by ID, not 178 * by ID and version. In some cases though, it may be desirable to preserve the version in resource 179 * links. In that case, this value should be set to <code>false</code>. 180 * 181 * @return Returns the parser instance's configuration setting for stripping versions from resource references when 182 * encoding. This method will return <code>null</code> if no value is set, in which case 183 * the value from the {@link ParserOptions} will be used (default is <code>true</code>) 184 * @see ParserOptions 185 */ 186 Boolean getStripVersionsFromReferences(); 187 188 /** 189 * If set to <code>true<code> (which is the default), resource references containing a version 190 * will have the version removed when the resource is encoded. This is generally good behaviour because 191 * in most situations, references from one resource to another should be to the resource by ID, not 192 * by ID and version. In some cases though, it may be desirable to preserve the version in resource 193 * links. In that case, this value should be set to <code>false</code>. 194 * <p> 195 * This method provides the ability to globally disable reference encoding. If finer-grained 196 * control is needed, use {@link #setDontStripVersionsFromReferencesAtPaths(String...)} 197 * </p> 198 * 199 * @param theStripVersionsFromReferences Set this to <code>false<code> to prevent the parser from removing resource versions from references (or <code>null</code> to apply the default setting from the {@link ParserOptions} 200 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 201 * @see #setDontStripVersionsFromReferencesAtPaths(String...) 202 * @see ParserOptions 203 */ 204 IParser setStripVersionsFromReferences(Boolean theStripVersionsFromReferences); 205 206 /** 207 * Is the parser in "summary mode"? See {@link #setSummaryMode(boolean)} for information 208 * 209 * @see #setSummaryMode(boolean) for information 210 */ 211 boolean isSummaryMode(); 212 213 /** 214 * If set to <code>true</code> (default is <code>false</code>) only elements marked by the FHIR specification as 215 * being "summary elements" will be included. 216 * <p> 217 * It is possible to modify the default summary mode element inclusions 218 * for this parser instance by invoking {@link #setEncodeElements(Set)} 219 * or {@link #setDontEncodeElements(Collection)}. It is also possible to 220 * modify the default summary mode element inclusions for all parsers 221 * generated for a given {@link FhirContext} by accessing 222 * {@link FhirContext#getParserOptions()} followed by 223 * {@link ParserOptions#setEncodeElementsForSummaryMode(Collection)} and/or 224 * {@link ParserOptions#setDontEncodeElementsForSummaryMode(Collection)}. 225 * </p> 226 * <p> 227 * For compatibility reasons with other frameworks, when encoding a 228 * <code>CapabilityStatement</code> resource in summary mode, extensions 229 * are always encoded, even though the FHIR Specification does not consider 230 * them to be summary elements. 231 * </p> 232 * 233 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 234 */ 235 IParser setSummaryMode(boolean theSummaryMode); 236 237 /** 238 * Parses a resource 239 * 240 * @param theResourceType The resource type to use. This can be used to explicitly specify a class which extends a built-in type 241 * (e.g. a custom type extending the default Patient class) 242 * @param theReader The reader to parse input from. Note that the Reader will not be closed by the parser upon completion. 243 * @return A parsed resource 244 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 245 */ 246 <T extends IBaseResource> T parseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException; 247 248 /** 249 * Parses a resource 250 * 251 * @param theResourceType The resource type to use. This can be used to explicitly specify a class which extends a built-in type 252 * (e.g. a custom type extending the default Patient class) 253 * @param theInputStream The InputStream to parse input from, <b>with an implied charset of UTF-8</b>. Note that the InputStream will not be closed by the parser upon completion. 254 * @return A parsed resource 255 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 256 */ 257 <T extends IBaseResource> T parseResource(Class<T> theResourceType, InputStream theInputStream) 258 throws DataFormatException; 259 260 /** 261 * Parses a resource 262 * 263 * @param theResourceType The resource type to use. This can be used to explicitly specify a class which extends a built-in type 264 * (e.g. a custom type extending the default Patient class) 265 * @param theString The string to parse 266 * @return A parsed resource 267 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 268 */ 269 <T extends IBaseResource> T parseResource(Class<T> theResourceType, String theString) throws DataFormatException; 270 271 /** 272 * Parses a resource 273 * 274 * @param theReader The reader to parse input from. Note that the Reader will not be closed by the parser upon completion. 275 * @return A parsed resource. Note that the returned object will be an instance of {@link IResource} or 276 * {@link IAnyResource} depending on the specific FhirContext which created this parser. 277 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 278 */ 279 IBaseResource parseResource(Reader theReader) throws ConfigurationException, DataFormatException; 280 281 /** 282 * Parses a resource 283 * 284 * @param theInputStream The InputStream to parse input from (charset is assumed to be UTF-8). 285 * Note that the stream will not be closed by the parser upon completion. 286 * @return A parsed resource. Note that the returned object will be an instance of {@link IResource} or 287 * {@link IAnyResource} depending on the specific FhirContext which created this parser. 288 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 289 */ 290 IBaseResource parseResource(InputStream theInputStream) throws ConfigurationException, DataFormatException; 291 292 /** 293 * Parses a resource 294 * 295 * @param theMessageString The string to parse 296 * @return A parsed resource. Note that the returned object will be an instance of {@link IResource} or 297 * {@link IAnyResource} depending on the specific FhirContext which created this parser. 298 * @throws DataFormatException If the resource can not be parsed because the data is not recognized or invalid for any reason 299 */ 300 IBaseResource parseResource(String theMessageString) throws ConfigurationException, DataFormatException; 301 302 /** 303 * If provided, specifies the elements which should NOT be encoded. Valid values for this 304 * field would include: 305 * <ul> 306 * <li><b>Patient</b> - Don't encode patient and all its children</li> 307 * <li><b>Patient.name</b> - Don't encode the patient's name</li> 308 * <li><b>Patient.name.family</b> - Don't encode the patient's family name</li> 309 * <li><b>*.text</b> - Don't encode the text element on any resource (only the very first position may contain a 310 * wildcard)</li> 311 * </ul> 312 * <p> 313 * Note: If {@link #setSummaryMode(boolean)} is set to <code>true</code>, then any 314 * elements specified using this method will be excluded even if they are 315 * summary elements. 316 * </p> 317 * <p> 318 * DSTU2 note: Note that values including meta, such as <code>Patient.meta</code> 319 * will work for DSTU2 parsers, but values with sub-elements on meta such 320 * as <code>Patient.meta.lastUpdated</code> will only work in 321 * DSTU3+ mode. 322 * </p> 323 * 324 * @param theDontEncodeElements The elements to not encode, or <code>null</code> 325 * @see #setEncodeElements(Set) 326 * @see ParserOptions#setDontEncodeElementsForSummaryMode(Collection) 327 */ 328 IParser setDontEncodeElements(@Nullable Collection<String> theDontEncodeElements); 329 330 /** 331 * If provided, specifies the elements which should NOT be encoded. Valid values for this 332 * field would include: 333 * <ul> 334 * <li><b>Patient</b> - Don't encode patient and all its children</li> 335 * <li><b>Patient.name</b> - Don't encode the patient's name</li> 336 * <li><b>Patient.name.family</b> - Don't encode the patient's family name</li> 337 * <li><b>*.text</b> - Don't encode the text element on any resource (only the very first position may contain a 338 * wildcard)</li> 339 * </ul> 340 * <p> 341 * DSTU2 note: Note that values including meta, such as <code>Patient.meta</code> 342 * will work for DSTU2 parsers, but values with sub-elements on meta such 343 * as <code>Patient.meta.lastUpdated</code> will only work in 344 * DSTU3+ mode. 345 * </p> 346 * 347 * @param theDontEncodeElements The elements to not encode. Can be an empty list, but must not be <code>null</code>. 348 * @see #setDontEncodeElements(Collection) 349 * @see ParserOptions#setDontEncodeElementsForSummaryMode(Collection) 350 * @since 7.4.0 351 */ 352 default IParser setDontEncodeElements(@Nonnull String... theDontEncodeElements) { 353 return setDontEncodeElements(CollectionUtil.newSet(theDontEncodeElements)); 354 } 355 356 /** 357 * If provided, specifies the elements which should be encoded, to the exclusion of all others. Valid values for this 358 * field would include: 359 * <ul> 360 * <li><b>Patient</b> - Encode patient and all its children</li> 361 * <li><b>Patient.name</b> - Encode only the patient's name</li> 362 * <li><b>Patient.name.family</b> - Encode only the patient's family name</li> 363 * <li><b>*.text</b> - Encode the text element on any resource (only the very first position may contain a 364 * wildcard)</li> 365 * <li><b>*.(mandatory)</b> - This is a special case which causes any mandatory fields (min > 0) to be encoded</li> 366 * </ul> 367 * <p> 368 * Note: If {@link #setSummaryMode(boolean)} is set to <code>true</code>, then any 369 * elements specified using this method will be included even if they are not 370 * summary elements. 371 * </p> 372 * 373 * @param theEncodeElements The elements to encode, or <code>null</code> 374 * @see #setDontEncodeElements(Collection) 375 * @see #setEncodeElements(String...) 376 * @see ParserOptions#setEncodeElementsForSummaryMode(Collection) 377 */ 378 IParser setEncodeElements(@Nullable Set<String> theEncodeElements); 379 380 /** 381 * If provided, specifies the elements which should be encoded, to the exclusion of all others. Valid values for this 382 * field would include: 383 * <ul> 384 * <li><b>Patient</b> - Encode patient and all its children</li> 385 * <li><b>Patient.name</b> - Encode only the patient's name</li> 386 * <li><b>Patient.name.family</b> - Encode only the patient's family name</li> 387 * <li><b>*.text</b> - Encode the text element on any resource (only the very first position may contain a 388 * wildcard)</li> 389 * <li><b>*.(mandatory)</b> - This is a special case which causes any mandatory fields (min > 0) to be encoded</li> 390 * </ul> 391 * <p> 392 * Note: If {@link #setSummaryMode(boolean)} is set to <code>true</code>, then any 393 * elements specified using this method will be included even if they are not 394 * summary elements. 395 * </p> 396 * 397 * @param theEncodeElements The elements to encode. Can be an empty list, but must not be <code>null</code>. 398 * @since 7.4.0 399 * @see #setEncodeElements(Set) 400 * @see ParserOptions#setEncodeElementsForSummaryMode(String...) 401 */ 402 default IParser setEncodeElements(@Nonnull String... theEncodeElements) { 403 return setEncodeElements(CollectionUtil.newSet(theEncodeElements)); 404 } 405 406 /** 407 * If set to <code>true</code> (default is false), the values supplied 408 * to {@link #setEncodeElements(Set)} will not be applied to the root 409 * resource (typically a Bundle), but will be applied to any sub-resources 410 * contained within it (i.e. search result resources in that bundle) 411 */ 412 boolean isEncodeElementsAppliesToChildResourcesOnly(); 413 414 /** 415 * If set to <code>true</code> (default is false), the values supplied 416 * to {@link #setEncodeElements(Set)} will not be applied to the root 417 * resource (typically a Bundle), but will be applied to any sub-resources 418 * contained within it (i.e. search result resources in that bundle) 419 */ 420 void setEncodeElementsAppliesToChildResourcesOnly(boolean theEncodeElementsAppliesToChildResourcesOnly); 421 422 /** 423 * Registers an error handler which will be invoked when any parse errors are found 424 * 425 * @param theErrorHandler The error handler to set. Must not be null. 426 */ 427 IParser setParserErrorHandler(IParserErrorHandler theErrorHandler); 428 429 /** 430 * Sets the "pretty print" flag, meaning that the parser will encode resources with human-readable spacing and 431 * newlines between elements instead of condensing output as much as possible. 432 * 433 * @param thePrettyPrint The flag 434 * @return Returns an instance of <code>this</code> parser so that method calls can be chained together 435 */ 436 IParser setPrettyPrint(boolean thePrettyPrint); 437 438 /** 439 * Sets the server's base URL used by this parser. If a value is set, resource references will be turned into 440 * relative references if they are provided as absolute URLs but have a base matching the given base. 441 * 442 * @param theUrl The base URL, e.g. "<a href="http://example.com/base">http://example.com/base</a>" 443 * @return Returns an instance of <code>this</code> parser so that method calls can be chained together 444 */ 445 IParser setServerBaseUrl(String theUrl); 446 447 /** 448 * If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's 449 * resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this 450 * to <code>false</code> if this is not the desired behavior (e.g. the client code wishes to perform additional 451 * validation checks between the fullUrl and the resource id). 452 * 453 * @param theOverrideResourceIdWithBundleEntryFullUrl Set this to <code>false</code> to prevent the parser from overriding resource ids with the 454 * Bundle.entry.fullUrl (or <code>null</code> to apply the default setting from the {@link ParserOptions}) 455 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 456 * @see ParserOptions 457 */ 458 IParser setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl); 459 460 /** 461 * If set to <code>true</code> (default is <code>false</code>), narratives will not be included in the encoded 462 * values. 463 */ 464 IParser setSuppressNarratives(boolean theSuppressNarratives); 465 466 /** 467 * Returns the value supplied to {@link IParser#setDontStripVersionsFromReferencesAtPaths(String...)} 468 * or <code>null</code> if no value has been set for this parser (in which case the default from 469 * the {@link ParserOptions} will be used). 470 * 471 * @see #setDontStripVersionsFromReferencesAtPaths(String...) 472 * @see #setStripVersionsFromReferences(Boolean) 473 * @see ParserOptions 474 */ 475 Set<String> getDontStripVersionsFromReferencesAtPaths(); 476 477 /** 478 * If supplied value(s), any resource references at the specified paths will have their 479 * resource versions encoded instead of being automatically stripped during the encoding 480 * process. This setting has no effect on the parsing process. 481 * <p> 482 * This method provides a finer-grained level of control than {@link #setStripVersionsFromReferences(Boolean)} 483 * and any paths specified by this method will be encoded even if {@link #setStripVersionsFromReferences(Boolean)} 484 * has been set to <code>true</code> (which is the default) 485 * </p> 486 * 487 * @param thePaths A collection of paths for which the resource versions will not be removed automatically 488 * when serializing, e.g. "Patient.managingOrganization" or "AuditEvent.object.reference". Note that 489 * only resource name and field names with dots separating is allowed here (no repetition 490 * indicators, FluentPath expressions, etc.). Set to <code>null</code> to use the value 491 * set in the {@link ParserOptions} 492 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 493 * @see #setStripVersionsFromReferences(Boolean) 494 * @see ParserOptions 495 */ 496 IParser setDontStripVersionsFromReferencesAtPaths(String... thePaths); 497 498 /** 499 * If supplied value(s), any resource references at the specified paths will have their 500 * resource versions encoded instead of being automatically stripped during the encoding 501 * process. This setting has no effect on the parsing process. 502 * <p> 503 * This method provides a finer-grained level of control than {@link #setStripVersionsFromReferences(Boolean)} 504 * and any paths specified by this method will be encoded even if {@link #setStripVersionsFromReferences(Boolean)} 505 * has been set to <code>true</code> (which is the default) 506 * </p> 507 * 508 * @param thePaths A collection of paths for which the resource versions will not be removed automatically 509 * when serializing, e.g. "Patient.managingOrganization" or "AuditEvent.object.reference". Note that 510 * only resource name and field names with dots separating is allowed here (no repetition 511 * indicators, FluentPath expressions, etc.). Set to <code>null</code> to use the value 512 * set in the {@link ParserOptions} 513 * @return Returns a reference to <code>this</code> parser so that method calls can be chained together 514 * @see #setStripVersionsFromReferences(Boolean) 515 * @see ParserOptions 516 */ 517 IParser setDontStripVersionsFromReferencesAtPaths(Collection<String> thePaths); 518 519 /** 520 * Parses an object fragment into the given structure. 521 * 522 * @param theSource The source value to parse and use to populate {@literal theTarget}. 523 * If {@literal theTarget} is an instance of {@link org.hl7.fhir.instance.model.api.IPrimitiveType} 524 * the value is treated as a simple string value. So for example, when populating 525 * a {@literal DateTimeTime}, the value should resemble 526 * {@literal 2020-01-01}, not {@literal <birthDate value="2020-01-01"/>}. 527 * If {@literal theTarget} is a complex structure, the value should be 528 * a container element suitable for the parser's encoding. So for example, 529 * if the target is an {@literal Identifier}, the value would be expected 530 * to resemble {@literal <identifier><system value="..."/><value value="..."/></identifier>} 531 * or <code>{"system":"...", "value":"..."}</code>. 532 * @param theTarget The target structure to populate. Note that this structure is not 533 * cleared automatically by the parser, so existing values will be 534 * overwritten only if {@literal theSource} has a value for the 535 * given element. 536 * @since 8.2.0 537 */ 538 default void parseInto(String theSource, IBase theTarget) { 539 try { 540 parseInto(new StringReader(theSource), theTarget); 541 } catch (IOException e) { 542 throw new InternalErrorException( 543 Msg.code(2634) + "Encountered IOException during read from - This should not happen!", e); 544 } 545 } 546 547 /** 548 * Parses an object fragment into the given structure. 549 * 550 * @param theSource The source value to parse and use to populate {@literal theTarget}. 551 * If {@literal theTarget} is an instance of {@link org.hl7.fhir.instance.model.api.IPrimitiveType} 552 * the value is treated as a simple string value. So for example, when populating 553 * a {@literal DateTimeTime}, the value should resemble 554 * {@literal 2020-01-01}, not {@literal <birthDate value="2020-01-01"/>}. 555 * If {@literal theTarget} is a complex structure, the value should be 556 * a container element suitable for the parser's encoding. So for example, 557 * if the target is an {@literal Identifier}, the value would be expected 558 * to resemble {@literal <identifier><system value="..."/><value value="..."/></identifier>} 559 * or <code>{"system":"...", "value":"..."}</code>. 560 * @param theTarget The target structure to populate. Note that this structure is not 561 * cleared automatically by the parser, so existing values will be 562 * overwritten only if {@literal theSource} has a value for the 563 * given element. 564 * @since 8.2.0 565 */ 566 void parseInto(Reader theSource, IBase theTarget) throws IOException; 567}