Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unwanted "is_a?" json key when using extract With an activerecord object #391

Open
silva96 opened this issue Mar 17, 2017 · 4 comments
Open
Labels

Comments

@silva96
Copy link

silva96 commented Mar 17, 2017

Hi, I'm using rails version 5.0.2 and jbuilder 2.6.3
Im having same problem as #116 , What could be possibly happening? because this bug was fixed

here is my view.json.jbuilder

json.(@booking, :api_data_schemas, :tickets_api_data_schemas)
json.seats @booking.seats do |seat|
  json.extract! seat, :id, :number_with_level, :bus_schedule_id, :seat_klass, :seat_klass_stars
  json.price seat.price.to_i
  json.price_usd seat.price_usd.to_f
end

and here is my json output: note the is_a? 2 times, appears as first attribute in extract! and json.(@booking, methods

{
  "is_a?": {},
  "api_data_schemas": {
    "outbound": {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "properties": {
        "departure_bus_stop": {
          "title": "Subida",
          "type": "integer",
          "values": [
            {
              "title": "TERMINAL SUR",
              "value": 1
            },
            {
              "title": "Cruce Colón",
              "value": 8
            }
          ]
        },
        "destination_bus_stop": {
          "title": "Bajada",
          "type": "integer",
          "values": [
            {
              "title": "TERMINAL OSORNO",
              "value": 5
            },
            {
              "title": "Cruce Los Tambores",
              "value": 29
            }
          ]
        }
      },
      "required": [
        "departure_bus_stop",
        "destination_bus_stop"
      ]
    }
  },
  "tickets_api_data_schemas": {},
  "seats": [
    {
      "is_a?": {},
      "id": 375,
      "number_with_level": "1-4",
      "bus_schedule_id": 417,
      "seat_klass": "2",
      "seat_klass_stars": 2,
      "price": 25000,
      "price_usd": 40.95
    }
  ]

Thanks in advance

@anton-ko
Copy link

@silva96 have you found a solution or a work around?
I'm dealing with the same issue :-/

@silva96
Copy link
Author

silva96 commented Oct 25, 2017

@anton-ko nope, I'm just ignoring it in the frontend.

@anton-ko
Copy link

@silva96 ugh.. thanks for the reply.

I've ended up with

JSON.parse(json).except(:is_a?).to_json

before returining to the API 🤦‍♂️

@robin850 robin850 added the bug label Nov 7, 2018
@rachitpant
Copy link

This bug is still present in the latest version of jbuilder (2.11.5). In addtion , in my case i am getting addtional key ==

Here is part of the output generated.
image

those two unwanted lines are generated by the following line in code.
json.responses_count institution_sport.responses_orgs.completed.count.to_i unless institution_sport.responses_orgs.blank?

For whatever reason , the key-value responses_count: 1 , that you see in the above screenshot does not print if i remove the to_i at the end. This might be an unrelated bug , but I mentioned it here , since it's happening due to the same line of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants