ComplexValue
open class ComplexValue : StructureBase, ComplexValueOrList, @unchecked Sendable
Encapsulates an OData complex value.
-
Decode the encoded data from the Decoder object and insantiate a new ComplexValue object from it.
See also
ComplexValue.encode(to encoder: Encoder)for usage examples how to encode and decode ComplexValue.Declaration
Swift
public required init(from decoder: Decoder) throwsParameters
fromdecoder object which contains the original object’s serialized data in a container instance
-
Encode the object instance
See also
EntityValue.decode(to encoder: Encoder)Example of encode/decode of a ComplexValue using proxy classes
open func encodeComplexValueExample() throws -> Void { let provider = OnlineODataProvider(serviceName: "TripPinService", serviceRoot: "http://services.odata.org/TripPinRESTierService/") let service = TripPinServiceProxy(provider: provider) let query = DataQuery() let complexValueToBeEncoded = try service.fetchPeople(matching: query).first?.addressInfo.first //get a ComplexValue // Encode the EntityValue with JSONEncoder (other encoder exists such as PropertyListEncoder) let encoder = JSONEncoder() if let encodedComplexValue = try? encoder.encode(complexValueToBeEncoded!) { if let json = String(data: encodedComplexValue, encoding: .utf8){ print(json) } // Decoding // JSONDecoder is used, but other decoders are available, such as PropertyListDecoder let decoder = JSONDecoder() // Add typeInfo to the decoder decoder.userInfo[CSDLDocument.csdlInfoKey] = service.metadata //Decode let decodedComplexValue = try? decoder.decode(ComplexValue.self, from: encodedComplexValue) } }Example of encode/decode of a ComplexValue using dynamic API
open func encodeComplexValueExample() throws -> Void { let provider = OnlineODataProvider(serviceName: "TripPinService", serviceRoot: "http://services.odata.org/TripPinRESTierService/") let service = TripPinServiceProxy(provider: provider) // Explicitly load metadata, then it must be cached manually. // The reason is, that type infos will not be implicitly encoded, but it will be needed at the encoding. // The dataservice's metadata contains all such type infos, so metadata will be first loaded then cached. service.serviceOptions.csdlOptions = ( service.serviceOptions.csdlOptions | CSDLOption.retainResolvedText | CSDLOption.retainOriginalText ) try service.loadMetadata() let metadataCachedAsString = service.metadata.originalText! // // Get the entity to be encoded by dynamic API let peopleEntitySet = service.entitySet(withName: "People") let query = DataQuery().from(peopleEntitySet) let entityValue = try service.executeQuery(query).entityList().first() let personEntityType = service.metadata.entityType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person") let propType = personEntityType.property(withName: "AddressInfo") let complexValueToBeEncoded = propType.complexList(from: entityValue).first() //get a ComplexValue // Encode the EntityValue with JSONEncoder (other encoder exists such as PropertyListEncoder) let encoder = JSONEncoder() if let encodedComplexValue = try? encoder.encode(complexValueToBeEncoded) { if let json = String(data: encodedComplexValue, encoding: .utf8){ print(json) // Check } // Decoding // JSONDecoder is used, but other decoders are available, such as PropertyListDecoder let decoder = JSONDecoder() // Get type infos from cached metadata parsing it to CSDLDocument let parser: CSDLParser = CSDLParser() parser.csdlOptions = (CSDLOption.processMixedVersions | CSDLOption.retainOriginalText | CSDLOption.resolveUndefinedTerms) var csdlDocument: CSDLDocument = parser.parseInProxy(metadataCachedAsString, url: "") // Add typeInfo to the decoder decoder.userInfo[CSDLDocument.csdlInfoKey] = csdlDocument // Decode let decodedComplexValue = try? decoder.decode(ComplexValue.self, from: encodedComplexValue) } }Declaration
Swift
public override func encode(to encoder: Encoder) throwsParameters
toencoder object which can be used to serialize the object’s data one by one into a container instance
-
Construct a new complex value. This constructor is intended for use by custom complex value subclasses. Use
ofTypefor regular construction.Declaration
Swift
public init(withDefaults: Bool = false, type: ComplexType? = nil, withIndexMap: SparseIndexMap? = nil)Parameters
withDefaultsShould
setDefaultValuesbe called to initialize properties with default values?typeComplex type. Should not be
nilexcept when called by generated proxy base classes.withIndexMapIf non-null, the created entities will use a sparse array implementation.
-
The complex type metadata for this value (
dataTypecast toComplexType).Declaration
Swift
public final var complexType: ComplexType { get } -
Declaration
Swift
open func copyComplex() -> ComplexValueReturn Value
A copy of this complex value (only structural properties are copied).
-
Declaration
Swift
override open func copyMutable() -> DataValueReturn Value
A clone of this value if it (together with all value subcomponents) is possibly mutable, or return
selfvalue if it (together with all value subcomponents) is definitely immutable. The resulting value might share mutable metadata with this query. -
Copy structural/dynamic property values from source complex value into this complex value.
Declaration
Swift
open func copyProperties(from: ComplexValue)Parameters
fromSource complex value.
-
Data type with a
DataType.codeofDataType.COMPLEX_VALUE.Declaration
Swift
override open var dataType: DataType { get } -
Declaration
Swift
open class func equal(a: ComplexValue?, b: ComplexValue?) -> BoolParameters
aFirst complex value.
bSecond complex value.
Return Value
trueif two complex values have equal structural properties. -
Construct a new complex value of the specified type.
Declaration
Swift
open class func ofType(_ type: ComplexType, sparse: SparseIndexMap? = nil) -> ComplexValueParameters
typeComplex type for the new value.
sparseSparse index map. For internal use.
Return Value
A new complex value.
-
Contains the original values for all structural properties of this complex value. Used by
DataService.updateEntityto determine the changed properties for PATCH requests.Declaration
Swift
public final var oldComplex: ComplexValue? { get set } -
The complex type metadata for this value (
dataTypecast toStructureType).Declaration
Swift
override open var structureType: StructureType { get } -
Convert this data value to a string. If the
dataTypeis defined by XML Schema Part 2: Datatypes, then the corresponding lexical format is used. JSON format is used for structured values (arrays and objects).Declaration
Swift
override open func toString() -> StringReturn Value
Lexical representation of this data value.
-
Data type code of the wrapped value, equivalent to
dataType.code.Declaration
Swift
override open var typeCode: Int { get }