Comments (2)
This goes slightly against the grain of what I originally set out to do with Oat, in that I wanted serializers to be as explicit as possible in their definition even if that means some duplication. The reason was that serializers should define a clear boundary between your model layer and your app's public HTTP API.
However, I can see how a more automatic mapping from "item" to "schema" attributes can be practical in some cases.
I'm not sure I would overload the properties
and property
methods to have the extra behaviour, as those methods are meant to be simple to understand and explicit in what the value is. Maybe we could add a separate method whose name describes the behaviour? For example map_properties
(or something better, maybe just map
). So your serializers would show a clear distinction between the definitions where you explicitly set the value and those where you just want to map them straight from the item.
class UserSerializer < ApplicationSerializer
schema do
map_properties :id, :email, :name, :created_at, :updated_at
property :age, item.years_old
property :psychic, item.psychic?
properties do |p|
p.active item.active?
end
end
end
Does that make sense?
from oat.
Yeah, I actually like #map_properties
a lot. Much clearer, and it lets us define it on the serializer to work for all adapters.
from oat.
Related Issues (20)
- Caching with Oat HOT 1
- Errors management HOT 2
- Thread Safety HOT 3
- JSONAPI linked entity names. HOT 7
- is lib/support/class_attribute necessary? HOT 5
- JSON API adapter should return id as a string HOT 2
- Oat, Rails Responders and hypermedia mime types HOT 3
- Array serialization HOT 1
- Nested serializers: undefined method HOT 4
- HAL support for multiple link objects per relationship? HOT 1
- Serialize to vanilla JSON using the same serializer class HOT 1
- Cross-cutting concerns HOT 2
- JsonApi adapter generates anything but JSON API conformant document HOT 2
- The Siren adapter renders multiple rels per link as an array of an array instead of a flat array
- An adapter for Hydra HOT 2
- :only option for filtering HOT 6
- Remove ActiveSupport
- Is it possible to don't serialize nil values ?
- JSON:API adapter not up-to-date with the spec
- Deserialization
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oat.