Suppose I have some class that defines ToString()
:
class Person {
public override string ToString() { /* ... */ }
}
And suppose an instance is contained in some model:
public Person Person { get; }
Then it is serialized like this:
"person": {
"value": "Foo Bar"
}
But what I expected was this:
"person": "Foo Bar"
Can I do this somehow, or must I use a custom converter?
UPDATE
No this is not a dupe of that linked question. That shows how to do two-way conversion to/from a type. I want to do one-way conversion, given my type already has a ToString
method - i.e. serialization only, not deserialization.
The question is not how to write a type converter - it is whether this one-way serialization is possible without a type converter.