Skip to content

Commit

Permalink
Merge pull request #27 from IBM-Swift/issue_846
Browse files Browse the repository at this point in the history
Have Bool serialized as true/false
  • Loading branch information
kweinmeister authored Nov 16, 2016
2 parents 9b339c1 + f3fb856 commit 64b0910
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/LclJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ private struct JSONWriter {
try serializeString(str)
} else if obj is Int || obj is Float || obj is Double || obj is UInt {
writer(String(describing: obj))
} else if let boolValue = obj as? Bool {
serializeBool(boolValue)
} else if let num = obj as? NSNumber {
try serializeNumber(num)
} else if let array = obj as? Array<Any> {
Expand Down Expand Up @@ -205,6 +207,15 @@ private struct JSONWriter {
writer("\"")
}

func serializeBool(_ bool: Bool) {
switch bool {
case true:
writer("true")
case false:
writer("false")
}
}

mutating func serializeNumber(_ num: NSNumber) throws {
if num.doubleValue.isInfinite || num.doubleValue.isNaN {
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.propertyListReadCorrupt.rawValue, userInfo: ["NSDebugDescription" : "Number cannot be infinity or NaN"])
Expand Down

0 comments on commit 64b0910

Please sign in to comment.