Comments (13)
If you add that in your app, I assume you get that behavior and everything works with Grape's format :xml
?
from grape-entity.
Yes, it works.
As for me it's a little inconsistency in gem's behavior.
It's strange that json works without any movements and xml doesn't.
If it's ok, then we can close this issue.
from grape-entity.
@agileanimal should make that call - at the least he/we might want to document this
from grape-entity.
thanks for fast response!
from grape-entity.
I am looking at this.
I personally don't use xml unless it is inside a plist, but I do think that there should be consistency.
That being said, Grape is used without Rails, so don't think the right solution is to introduce a dependencies on Active Support.
from grape-entity.
There is already dependency on ActiveSupport :)
https://github.com/intridea/grape/blob/master/grape.gemspec#L20
from grape-entity.
I'm thinking that the proper thing to do here is actually to strip out to_json
and remove the MultiJson dependency. Entity is a way of creating a structured representation of data. Let Grape do the serialization of that structure. I say we leave things be with serializable_hash
and as_json
and allow consumers of the library to do the actual JSON/XML conversion.
@dblock @agileanimal thoughts on this?
from grape-entity.
@mbleigh Right on.
from grape-entity.
@mbleigh I agree too.
from grape-entity.
Another option to consider: configurable serializers. Consider something like the following in eg a Rails initializer:
Grape::Entity.configure do
json do |ent, opts|
MultiJson.dump(e)
end
xml do |ent, opts|
ent.to_xml(opts)
end
end
In the case of a Rails application, a default railtie can be provided to setup serializers for json and xml. If someone is using standalone Grape (or even just Grape::Entity in a Rack app), they just need to initialize the serializer somewhere. In any case, I'm interested in preserving the utility of Grape::Entity outside of just Grape apps.
from grape-entity.
I don't think leaving out to_json
and to_xml
inhibits usability outside of Grape, and it keeps the dependencies of grape-entity
to a minimum.
MultiJson.dump(some_entity.as_json)
from grape-entity.
@SegFaultAX I feel that your proposal does the same job as Grape formatters, in possibly a more elegant way. I would be open to allow blocks for formatters in Grape proper, currently you have to do a lambda.
from grape-entity.
So we had an interesting chat here with some action items. Where're my pull requests? What I am paying you guys for? j/k :)
from grape-entity.
Related Issues (20)
- How to get the specified expose
- Adding default value to expose
- Version 0.8 compatibility with grape 1.3.1 HOT 3
- Why docs suggest strings for root option? HOT 1
- Sending an array of hash HOT 1
- Proxy API modeling HOT 1
- Grape::Entity#as_json does not return a recursive set of hashes.
- Ruby 3: Entities exposing fields via Symbol#to_proc are broken HOT 3
- Frozen/Deadlocked Ruby thread instead of NoMethodError HOT 1
- expose_nil option doesn't respect Entity.hash_access
- Same name nested arguments get value from root HOT 5
- Inheritance issue with the entity HOT 2
- Inheritance issue with the grape-entity version >= 0.5.0
- `FetchableObject` can cause unexpected behavior HOT 4
- Override Grape Entity Model Description
- Truncate Formatter
- Expose default value doesn't work for me HOT 2
- `expose_nil:` conflicts with options passing to a block
- `route.entity` can not get entity class in Rails 7.1
- Custom Entity options support
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 grape-entity.