Skip to content

Commit 64b0910

Browse files
authored
Merge pull request #27 from IBM-Swift/issue_846
Have Bool serialized as true/false
2 parents 9b339c1 + f3fb856 commit 64b0910

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Source/LclJSONSerialization.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ private struct JSONWriter {
159159
try serializeString(str)
160160
} else if obj is Int || obj is Float || obj is Double || obj is UInt {
161161
writer(String(describing: obj))
162+
} else if let boolValue = obj as? Bool {
163+
serializeBool(boolValue)
162164
} else if let num = obj as? NSNumber {
163165
try serializeNumber(num)
164166
} else if let array = obj as? Array<Any> {
@@ -205,6 +207,15 @@ private struct JSONWriter {
205207
writer("\"")
206208
}
207209

210+
func serializeBool(_ bool: Bool) {
211+
switch bool {
212+
case true:
213+
writer("true")
214+
case false:
215+
writer("false")
216+
}
217+
}
218+
208219
mutating func serializeNumber(_ num: NSNumber) throws {
209220
if num.doubleValue.isInfinite || num.doubleValue.isNaN {
210221
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.propertyListReadCorrupt.rawValue, userInfo: ["NSDebugDescription" : "Number cannot be infinity or NaN"])

0 commit comments

Comments
 (0)