Comments (8)
Yes, I agree with the concept @xbill82.
I suggest to have an option which is a function that maps the attribute instead of having options like dasherize: true
or camelCase:true
or even underscore: true
.
Something like:
keyForAttribute: function (attribute) { return camelCase(attribute); }
Thoughts?
from jsonapi-serializer.
Yeah, sounds fair!
So, this way the attributes
field would become an object
instead of an array
? I say this because of the key: function
structure you suggest...
from jsonapi-serializer.
And, also, there could be a couple of dasherize(attr)
, camelCase(attr)
and underscore(attr)
functions provided by the main JsonApiSerializer
class, e.g.
new JsonApiSerializer('users', dataSet, {
apiEndpoint: 'http://localhost:3000/api',
attributes: {'firstName': function(attr){ return JsonApiSerializer.camelCase(attr)} },
}
from jsonapi-serializer.
@xbill82 The master branch has been updated to have this new feature. Example:
var inflection = require('inflection');
new JsonApiSerializer('users', dataSet, {
apiEndpoint: 'http://localhost:3000/api',
attributes: ['firstName', 'lastName'],
keyForAttribute: function (attribute) {
return inflection.camelCase(attribute);
}
}
Thoughts? Does it fix your problem?
from jsonapi-serializer.
Sounds terrific. 👍
Just one thing: are you sure the name keyForAttribute
would be easy to understand? I think we're dealing with attribute key transform, so I'd suggest something like transformAttributeKeys
or something similar.
Would be happy to read your thoughts about it.
from jsonapi-serializer.
No, I'm not sure :) Ember.js uses this name to do the same thing:
http://emberjs.com/api/data/classes/DS.JSONSerializer.html#method_keyForAttribute
from jsonapi-serializer.
Good point! Ember is a great source of inspiration for conventions and habits! Great job!
from jsonapi-serializer.
Thanks @xbill82 !
from jsonapi-serializer.
Related Issues (20)
- feat: On deserialization it would be nice if the meta, links, etc, are available as a Symbol in the data
- How can I build deep relationships with my serializer HOT 1
- Automatically calculate attribute list
- 3.6.6 breaks deep relations HOT 4
- What is the difference between `ref` and `id`? HOT 2
- Strange issue with nested relationship deserializing HOT 3
- Support has died. See description. HOT 2
- deserialize does not deserializer links inside relationships objects HOT 3
- Express inside examples is set to version 0.0.0.0 which detects it as vulnerable by scanning tools like Twistlock
- falsy JavaScript attribute values are getting set to null if nullIfMissing flag is set
- How to deserialize with different type?
- Can't Make Relationship Work
- Ability to prefix 'meta' and 'links' key on deserialization HOT 1
- Deserializer [relationships] without [included] field wont work HOT 1
- would not be nice to have a generic valueForRelationship? HOT 1
- How to show all atributte relationships?
- Slow deserialization for specific input HOT 1
- Is it possible to customize the value of the type key? HOT 1
- meta data for Resource Identifier Objects
- Express name throws vulnerability error
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 jsonapi-serializer.