@@ -246,6 +246,7 @@ internal extension TransformationFromJSON {
246246 private static func letStatementForPrimitiveValue( _ attributeName: String , _ propertyName: String , _ type: SwiftPrimitiveValueType ) -> LineOfCode {
247247 switch type {
248248 case . any: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? Any "
249+ case . emptyArray: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? [Any?] "
249250 case . bool, . int, . string: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? \( type. name) "
250251 case . double: return " let \( propertyName) = Double(json: json, key: \" \( attributeName) \" ) " // Allows an integer to be interpreted as a double.
251252 case . url: return " let \( propertyName) = URL(json: json, key: \" \( attributeName) \" ) "
@@ -267,16 +268,17 @@ internal extension TransformationFromJSON {
267268
268269 private static func letStatementForArrayOfOptionalPrimitiveValues( _ attributeName: String , _ propertyName: String , _ elementType: SwiftPrimitiveValueType ) -> LineOfCode {
269270 switch elementType {
270- case . any, . bool, . int, . string: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalValueArray() as [ \( elementType. name) ?] }) "
271- case . date( let format) : return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalDateArray(withFormat: \" \( format) \" ) }) "
272- case . double: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalDoubleArray() }) "
273- case . url: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalURLArray() }) "
271+ case . any, . bool, . int, . string, . emptyArray : return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalValueArray() as [ \( elementType. name) ?] }) "
272+ case . date( let format) : return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalDateArray(withFormat: \" \( format) \" ) }) "
273+ case . double: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalDoubleArray() }) "
274+ case . url: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [Any]).map({ $0.toOptionalURLArray() }) "
274275 }
275276 }
276277
277278 private static func letStatementForArrayOfRequiredPrimitiveValues( _ attributeName: String , _ propertyName: String , _ elementType: SwiftPrimitiveValueType ) -> LineOfCode {
278279 switch elementType {
279280 case . any: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? [Any?] " // Any is treated as optional.
281+ case . emptyArray: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? [[Any?]] "
280282 case . bool, . int, . string: return " let \( propertyName) = json[ \" \( attributeName) \" ] as? [ \( elementType. name) ] "
281283 case . date( let format) : return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [String]).flatMap({ $0.toDateArray(withFormat: \" \( format) \" ) }) "
282284 case . double: return " let \( propertyName) = (json[ \" \( attributeName) \" ] as? [NSNumber]).map({ $0.toDoubleArray() }) "
@@ -288,13 +290,14 @@ internal extension TransformationFromJSON {
288290fileprivate extension SwiftPrimitiveValueType {
289291 var name : String {
290292 switch self {
291- case . any: return " Any "
292- case . bool: return " Bool "
293- case . date: return " Date "
294- case . double: return " Double "
295- case . int: return " Int "
296- case . string: return " String "
297- case . url: return " URL "
293+ case . any: return " Any "
294+ case . bool: return " Bool "
295+ case . date: return " Date "
296+ case . double: return " Double "
297+ case . emptyArray: return " [Any?] "
298+ case . int: return " Int "
299+ case . string: return " String "
300+ case . url: return " URL "
298301 }
299302 }
300303}
0 commit comments