I just implemented a serializer for a class as follow:
import {File} from './file'
import Serialization from './serializable'
class User implements Serialization<User> {
username: string
deserialize(input) {
this.username = input.username
return this
}
}
Some details are omitted
However, I thought to do serialization and convert this object into Json, I need to implement a serializer which is reverse to what I wrote in this deserializer
But the puzzling thing is, when I do:
app.use('/abc', (req, res) => {
getLoggedInUser(sessionToken)
.then(
user => {
const tmp: User = s
res.send(tmp)
}
).catch(
err => {
console.log("err =" + JSON.stringify(err))
}
)
express actually returned the JSON version of this User object.
I'm quite surprised by this behavior. Does that mean I don't need a serializer since it's done by typescript automatically? Or am I missing something?