diff --git a/Sources/OpenFoodFacts/types/Product.swift b/Sources/OpenFoodFacts/types/Product.swift index 93d2c3d..99a713f 100644 --- a/Sources/OpenFoodFacts/types/Product.swift +++ b/Sources/OpenFoodFacts/types/Product.swift @@ -535,7 +535,27 @@ public class Product: Codable, ObjectDebugger { lastImageDatesTags = try container.decodeIfPresent([String].self, forKey: .lastImageDatesTags) lastImageT = try container.decodeIfPresent(Float.self, forKey: .lastImageT) lastModifiedBy = try container.decodeIfPresent(String.self, forKey: .lastModifiedBy) - lastModifiedT = try container.decodeIfPresent(Float.self, forKey: .lastModifiedT) + if container.contains(.lastModifiedT) { + if try container.decodeNil(forKey: .maxImgid) { + lastModifiedT = nil + } else { + if let floatValue = try? container.decode(Float.self, forKey: .lastModifiedT) { + lastModifiedT = floatValue + } else if let stringValue = try? container.decode(String.self, forKey: .lastModifiedT) { + lastModifiedT = Float(stringValue) + }else { + // If decoding as both Float and String fails, handle the error accordingly + throw DecodingError.dataCorruptedError( + forKey: .lastModifiedT, + in: container, + debugDescription: "Unable to decode lastModifiedT" + ) + } + + } + } else { + lastModifiedT = nil + } lc = try container.decodeIfPresent(String.self, forKey: .lc) link = try container.decodeIfPresent(String.self, forKey: .link) linkDebugTags = try container.decodeIfPresent([String].self, forKey: .linkDebugTags)