mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
cab6313798
* Add (failing) test for Subclass JSON encoding * Allow subclasses of known types to be encoded with superclass encoder * Add change file * Add documentation, fix custom json_encoders and add unit test Blacken doc Fix test that worked on my machine datetime.timestamp() is flakey? Single quotes only * Reduce lookups - Remove last element in `__mro__` as it will always be `object` - Use .get for compactness * Regarding the loop * Move Path and Enum into ENCODERS_BY_TYPE Sort ENCODERS_BY_TYPE * improve JSON docs Co-authored-by: Samuel Colvin <s@muelcolvin.com>
13 lines
268 B
Python
13 lines
268 B
Python
from datetime import datetime
|
|
from pydantic import BaseModel
|
|
|
|
class BarModel(BaseModel):
|
|
whatever: int
|
|
|
|
class FooBarModel(BaseModel):
|
|
foo: datetime
|
|
bar: BarModel
|
|
|
|
m = FooBarModel(foo=datetime(2032, 6, 1, 12, 13, 14), bar={'whatever': 123})
|
|
print(m.json())
|