swift6.CodableHelper.mustache Maven / Gradle / Ivy
The newest version!
//
// CodableHelper.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//
import Foundation
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class CodableHelper: @unchecked Sendable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init() {}
private var customDateFormatter: DateFormatter?
private var defaultDateFormatter: DateFormatter = OpenISO8601DateFormatter()
private var customJSONDecoder: JSONDecoder?
private lazy var defaultJSONDecoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(dateFormatter)
return decoder
}()
private var customJSONEncoder: JSONEncoder?
private lazy var defaultJSONEncoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .formatted(dateFormatter)
encoder.outputFormatting = .prettyPrinted
return encoder
}()
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var dateFormatter: DateFormatter {
get { return customDateFormatter ?? defaultDateFormatter }
set { customDateFormatter = newValue }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var jsonDecoder: JSONDecoder {
get { return customJSONDecoder ?? defaultJSONDecoder }
set { customJSONDecoder = newValue }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var jsonEncoder: JSONEncoder {
get { return customJSONEncoder ?? defaultJSONEncoder }
set { customJSONEncoder = newValue }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func decode(_ type: T.Type, from data: Data) -> Swift.Result where T: Decodable {
return Swift.Result { try jsonDecoder.decode(type, from: data) }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func encode(_ value: T) -> Swift.Result where T: Encodable {
return Swift.Result { try jsonEncoder.encode(value) }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy