jbuilder icon indicating copy to clipboard operation
jbuilder copied to clipboard

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

Open silva96 opened this issue 8 years ago • 4 comments

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

silva96 avatar Mar 17 '17 19:03 silva96

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

anton-ko avatar Oct 25 '17 20:10 anton-ko

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

silva96 avatar Oct 25 '17 20:10 silva96

@silva96 ugh.. thanks for the reply.

I've ended up with

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

before returining to the API 🤦‍♂️

anton-ko avatar Oct 25 '17 20:10 anton-ko

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.

rachitpant avatar Mar 10 '23 21:03 rachitpant