Skip to content

Add custom JSON encoder / decoder support #189

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

Merged
merged 1 commit into from
Jul 28, 2020
Merged

Conversation

tanner0101
Copy link
Member

@tanner0101 tanner0101 commented Jul 28, 2020

Adds support for configuring which JSON coders MySQL uses when serializing nested data to the database (#189).

// Setup custom JSON coders that use unix timestamps
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .secondsSince1970
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970

// Configure MySQL database.
app.databaes.use(.mysql(
    configuration: ..., 
    encoder: MySQLDataEncoder(json: encoder), 
    decoder: MySQLDataDecoder(json: decoder)
))

Note that for dates specifically, you can use @Timestamp formats to configure formatting per field.

@tanner0101 tanner0101 added bug Something isn't working enhancement New feature or request semver-minor Contains new APIs labels Jul 28, 2020
@tanner0101
Copy link
Member Author

Adds changes from vapor/mysql-kit#285

@tanner0101 tanner0101 merged commit 290ff55 into master Jul 28, 2020
@tanner0101 tanner0101 deleted the tn-json-coders branch July 28, 2020 15:11
@tanner0101
Copy link
Member Author

These changes are now available in 4.0.0-rc.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request semver-minor Contains new APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant