Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoder.encode("1") debugDescription : "Top-level String encoded as string JSON fragment." #2335

Open
Toj-dev opened this issue Jan 5, 2024 · 1 comment

Comments

@Toj-dev
Copy link

Toj-dev commented Jan 5, 2024

// debugDescription : "Top-level String encoded as string JSON fragment."

mutating func encoded(encodable: Encodable, encoder: JSONEncoder = JSONEncoder()) throws -> URLRequest {
do {
let encodable = AnyEncodable(encodable)

        // encodable is  primary data type(int / double/ string)
        httpBody = try encoder.encode(encodable)

        let contentTypeHeaderName = "Content-Type"
        if value(forHTTPHeaderField: contentTypeHeaderName) == nil {
            setValue("application/json", forHTTPHeaderField: contentTypeHeaderName)
        }

        return self
    } catch { 
        throw MoyaError.encodableMapping(error)
    }
}
@Toj-dev
Copy link
Author

Toj-dev commented Jan 5, 2024

iPhone 5s
iOS12.5.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant