Code Monkey home page Code Monkey logo

Comments (13)

dblock avatar dblock commented on May 18, 2024

If you add that in your app, I assume you get that behavior and everything works with Grape's format :xml?

from grape-entity.

alovak avatar alovak commented on May 18, 2024

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.

dblock avatar dblock commented on May 18, 2024

@agileanimal should make that call - at the least he/we might want to document this

from grape-entity.

alovak avatar alovak commented on May 18, 2024

thanks for fast response!

from grape-entity.

idyll avatar idyll commented on May 18, 2024

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.

alovak avatar alovak commented on May 18, 2024

There is already dependency on ActiveSupport :)

https://github.com/intridea/grape/blob/master/grape.gemspec#L20

from grape-entity.

mbleigh avatar mbleigh commented on May 18, 2024

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.

dblock avatar dblock commented on May 18, 2024

@mbleigh Right on.

from grape-entity.

idyll avatar idyll commented on May 18, 2024

@mbleigh I agree too.

from grape-entity.

SegFaultAX avatar SegFaultAX commented on May 18, 2024

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.

mbleigh avatar mbleigh commented on May 18, 2024

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.

dblock avatar dblock commented on May 18, 2024

@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.

dblock avatar dblock commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.