Closed Barlog951 closed 8 years ago
I ran the test with no errors.
irb(main):001:0> j = '{"cursor":{"next":null},"customers":[{"id":"2d5ded172fad40598cc99fc7eeb2eaca","source":"unknown","created_at":"2016-05-25T16:28:37.364Z"},{"id":"10e9f8b6d72c44c09cd1a559cf782a78","source":"unknown","created_at":"2016-05-25T16:28:37.359Z"},{"id":"66e8fd9a9b664f1996d2c7749945d76f","source":"unknown","created_at":"2016-05-25T16:28:37.353Z"},{"id":"c527a1ef20774acd825cdc42ef6cbedc","source":"unknown","created_at":"2016-05-25T16:28:37.348Z"},{"id":"bc9ce4093ee9400b9f0f48a043a490bb","source":"unknown","created_at":"2016-05-25T16:28:37.343Z"}]}'
=> "{\"cursor\":{\"next\":null},\"customers\":[{\"id\":\"2d5ded172fad40598cc99fc7eeb2eaca\",\"source\":\"unknown\",\"created_at\":\"2016-05-25T16:28:37.364Z\"},{\"id\":\"10e9f8b6d72c44c09cd1a559cf782a78\",\"source\":\"unknown\",\"created_at\":\"2016-05-25T16:28:37.359Z\"},{\"id\":\"66e8fd9a9b664f1996d2c7749945d76f\",\"source\":\"unknown\",\"created_at\":\"2016-05-25T16:28:37.353Z\"},{\"id\":\"c527a1ef20774acd825cdc42ef6cbedc\",\"source\":\"unknown\",\"created_at\":\"2016-05-25T16:28:37.348Z\"},{\"id\":\"bc9ce4093ee9400b9f0f48a043a490bb\",\"source\":\"unknown\",\"created_at\":\"2016-05-25T16:28:37.343Z\"}]}"
irb(main):002:0> Oj.load(j)
=> {"cursor"=>{"next"=>nil}, "customers"=>[{"id"=>"2d5ded172fad40598cc99fc7eeb2eaca", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.364Z"}, {"id"=>"10e9f8b6d72c44c09cd1a559cf782a78", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.359Z"}, {"id"=>"66e8fd9a9b664f1996d2c7749945d76f", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.353Z"}, {"id"=>"c527a1ef20774acd825cdc42ef6cbedc", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.348Z"}, {"id"=>"bc9ce4093ee9400b9f0f48a043a490bb", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.343Z"}]}
irb(main):003:0> Oj.mimic_JSON
=> JSON
irb(main):004:0> JSON.parse(j)
=> {"cursor"=>{"next"=>nil}, "customers"=>[{"id"=>"2d5ded172fad40598cc99fc7eeb2eaca", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.364Z"}, {"id"=>"10e9f8b6d72c44c09cd1a559cf782a78", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.359Z"}, {"id"=>"66e8fd9a9b664f1996d2c7749945d76f", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.353Z"}, {"id"=>"c527a1ef20774acd825cdc42ef6cbedc", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.348Z"}, {"id"=>"bc9ce4093ee9400b9f0f48a043a490bb", "source"=>"unknown", "created_at"=>"2016-05-25T16:28:37.343Z"}]}
irb(main):005:0>
You are calling JSON.parse. Did you call Oj.mimic_JSON or are you using the JSON gem?
this is my test
it 'returns 200 and entries containing only users organizations interactions for GET ALL' do
get '/customers'
expect(last_response.status).to eq(200)
expect(JSON.parse(last_response.body)['customers'].count).to eq(5)
end
point for simulate this error is call get '/customers'
(response is json)
JSON.parse is not even call
this test pass correct
it 'test json parser' do
simple_parse = JSON.parse('{}')
parse = JSON.parse('{"cursor":{"next":null},"customers":[{"id":"2d5ded172fad40598cc99fc7eeb2eaca","source":"unknown","created_at":"2016-05-25T16:28:37.364Z"},{"id":"10e9f8b6d72c44c09cd1a559cf782a78","source":"unknown","created_at":"2016-05-25T16:28:37.359Z"},{"id":"66e8fd9a9b664f1996d2c7749945d76f","source":"unknown","created_at":"2016-05-25T16:28:37.353Z"},{"id":"c527a1ef20774acd825cdc42ef6cbedc","source":"unknown","created_at":"2016-05-25T16:28:37.348Z"},{"id":"bc9ce4093ee9400b9f0f48a043a490bb","source":"unknown","created_at":"2016-05-25T16:28:37.343Z"}]}')
expect(simple_parse.empty?).to eq(TRUE)
expect(parse['customers'].count).to eq(5)
end
wen i try run tests without oj gem everything pass correctly
I don't see Oj being called in any of your tests. Are you calling Oj.mimic_JSON somewhere else?
no i dont call Oj.mimic_JSON directly
this is /customers endpoint code
get '/customers' do
model = CustomerCollectionViewModel.new(organization!)
model.paginate(params['cursor'])
json({ cursor: model.cursor, customers: model.to_json })
end
model.to_json metode
def to_json(options={})
ExternalClientDecorator.represent(@customers.to_a)
end
Is this crash in the server or the client?
this is crash in server
call json({ cursor: model.cursor, customers: model.to_json })
use JSON gem
i try use Oj.dump({ cursor: model.cursor, customers: model.to_json }, mode: :compat)
but same result
uff i figure it one interesting thing
model.to_json got me a object (it is not a my code :D )
def to_json(options={})
ExternalClientDecorator.represent(@customers.to_a)
end
foo = model.to_json
i can run foo.to_json and i got correct json
solution of crash is call json({ cursor: model.cursor, customers: JSON.parse(model.to_json.to_json)})
but this is a stupid solution :/
That is not a good solution. I agree. Also odd that model.to_json does not return a JSON string.
I know, i will rewrite this method
but JSON.parse(ExternalClientDecorator.represent(@customers.to_a).to_json)
is not a (correct) solution of problem
when i doesn't use oj this just past without changes of code
You are using multi_json which will use different JSON encoders depending on what you have installed. Oj is preferred over the JSON gem so if it is installed it will be used. I would like to find out what object is being sent to the encoder. It sounds like model. Can you print out the model class and possible the content?
all in model class
--- !ruby/object:CustomerCollectionViewModel
customers:
- !ruby/object:ExternalClient
raw_attributes:
id: f566a7fb-924b-4e2a-90b0-ded3a6c2ef03
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.244568'
updated_at: '2016-05-25 19:24:13.244568'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types: &6
id: &1 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid
precision:
scale:
limit:
organization_id: *1
external_id: &2 !ruby/object:ActiveRecord::Type::String
precision:
scale:
limit:
name: *2
email: *2
phone: *2
created_at: &3 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime
precision:
scale:
limit:
updated_at: *3
source: *2
salutation: *2
unsubscribed: &4 !ruby/object:ActiveRecord::Type::Boolean
precision:
scale:
limit:
language: *2
country: *2
attribute1: *2
attribute2: *2
attribute3: *2
attribute4: *2
attribute5: *2
attribute6: *2
attribute7: *2
attribute8: *2
attribute9: *2
gender: &5 !ruby/object:ActiveRecord::Type::String
precision:
scale:
limit: 1
attribute10: *2
values:
id: f566a7fb-924b-4e2a-90b0-ded3a6c2ef03
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.244568'
updated_at: '2016-05-25 19:24:13.244568'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
additional_types: &7 {}
materialized: true
delegate_hash:
id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: id
value_before_type_cast: f566a7fb-924b-4e2a-90b0-ded3a6c2ef03
type: *1
organization_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: organization_id
value_before_type_cast: b4b511aa-5547-42e6-b00b-db71f7b40750
type: *1
external_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: external_id
value_before_type_cast:
type: *2
name: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: name
value_before_type_cast:
type: *2
email: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: email
value_before_type_cast:
type: *2
phone: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: phone
value_before_type_cast:
type: *2
created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: created_at
value_before_type_cast: '2016-05-25 19:24:13.244568'
type: *3
updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: updated_at
value_before_type_cast: '2016-05-25 19:24:13.244568'
type: *3
source: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: source
value_before_type_cast:
type: *2
salutation: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: salutation
value_before_type_cast:
type: *2
unsubscribed: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: unsubscribed
value_before_type_cast: f
type: *4
language: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: language
value_before_type_cast:
type: *2
country: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: country
value_before_type_cast:
type: *2
attribute1: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute1
value_before_type_cast:
type: *2
attribute2: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute2
value_before_type_cast:
type: *2
attribute3: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute3
value_before_type_cast:
type: *2
attribute4: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute4
value_before_type_cast:
type: *2
attribute5: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute5
value_before_type_cast:
type: *2
attribute6: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute6
value_before_type_cast:
type: *2
attribute7: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute7
value_before_type_cast:
type: *2
attribute8: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute8
value_before_type_cast:
type: *2
attribute9: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute9
value_before_type_cast:
type: *2
gender: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: gender
value_before_type_cast:
type: *5
attribute10: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute10
value_before_type_cast:
type: *2
new_record: false
active_record_yaml_version: 0
- !ruby/object:ExternalClient
raw_attributes:
id: 36b85fe4-116c-456d-82de-39d5e93f4c71
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.239632'
updated_at: '2016-05-25 19:24:13.239632'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types: *6
values:
id: 36b85fe4-116c-456d-82de-39d5e93f4c71
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.239632'
updated_at: '2016-05-25 19:24:13.239632'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
additional_types: *7
materialized: true
delegate_hash:
id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: id
value_before_type_cast: 36b85fe4-116c-456d-82de-39d5e93f4c71
type: *1
organization_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: organization_id
value_before_type_cast: b4b511aa-5547-42e6-b00b-db71f7b40750
type: *1
external_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: external_id
value_before_type_cast:
type: *2
name: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: name
value_before_type_cast:
type: *2
email: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: email
value_before_type_cast:
type: *2
phone: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: phone
value_before_type_cast:
type: *2
created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: created_at
value_before_type_cast: '2016-05-25 19:24:13.239632'
type: *3
updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: updated_at
value_before_type_cast: '2016-05-25 19:24:13.239632'
type: *3
source: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: source
value_before_type_cast:
type: *2
salutation: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: salutation
value_before_type_cast:
type: *2
unsubscribed: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: unsubscribed
value_before_type_cast: f
type: *4
language: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: language
value_before_type_cast:
type: *2
country: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: country
value_before_type_cast:
type: *2
attribute1: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute1
value_before_type_cast:
type: *2
attribute2: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute2
value_before_type_cast:
type: *2
attribute3: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute3
value_before_type_cast:
type: *2
attribute4: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute4
value_before_type_cast:
type: *2
attribute5: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute5
value_before_type_cast:
type: *2
attribute6: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute6
value_before_type_cast:
type: *2
attribute7: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute7
value_before_type_cast:
type: *2
attribute8: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute8
value_before_type_cast:
type: *2
attribute9: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute9
value_before_type_cast:
type: *2
gender: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: gender
value_before_type_cast:
type: *5
attribute10: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute10
value_before_type_cast:
type: *2
new_record: false
active_record_yaml_version: 0
- !ruby/object:ExternalClient
raw_attributes:
id: a253cd4c-c185-4e88-9f54-d40114e0c983
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.232541'
updated_at: '2016-05-25 19:24:13.232541'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types: *6
values:
id: a253cd4c-c185-4e88-9f54-d40114e0c983
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.232541'
updated_at: '2016-05-25 19:24:13.232541'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
additional_types: *7
materialized: true
delegate_hash:
id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: id
value_before_type_cast: a253cd4c-c185-4e88-9f54-d40114e0c983
type: *1
organization_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: organization_id
value_before_type_cast: b4b511aa-5547-42e6-b00b-db71f7b40750
type: *1
external_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: external_id
value_before_type_cast:
type: *2
name: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: name
value_before_type_cast:
type: *2
email: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: email
value_before_type_cast:
type: *2
phone: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: phone
value_before_type_cast:
type: *2
created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: created_at
value_before_type_cast: '2016-05-25 19:24:13.232541'
type: *3
updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: updated_at
value_before_type_cast: '2016-05-25 19:24:13.232541'
type: *3
source: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: source
value_before_type_cast:
type: *2
salutation: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: salutation
value_before_type_cast:
type: *2
unsubscribed: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: unsubscribed
value_before_type_cast: f
type: *4
language: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: language
value_before_type_cast:
type: *2
country: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: country
value_before_type_cast:
type: *2
attribute1: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute1
value_before_type_cast:
type: *2
attribute2: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute2
value_before_type_cast:
type: *2
attribute3: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute3
value_before_type_cast:
type: *2
attribute4: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute4
value_before_type_cast:
type: *2
attribute5: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute5
value_before_type_cast:
type: *2
attribute6: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute6
value_before_type_cast:
type: *2
attribute7: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute7
value_before_type_cast:
type: *2
attribute8: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute8
value_before_type_cast:
type: *2
attribute9: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute9
value_before_type_cast:
type: *2
gender: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: gender
value_before_type_cast:
type: *5
attribute10: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute10
value_before_type_cast:
type: *2
new_record: false
active_record_yaml_version: 0
- !ruby/object:ExternalClient
raw_attributes:
id: 3feae596-a0ee-41c9-befd-c2d0fef4fd30
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.225395'
updated_at: '2016-05-25 19:24:13.225395'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types: *6
values:
id: 3feae596-a0ee-41c9-befd-c2d0fef4fd30
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.225395'
updated_at: '2016-05-25 19:24:13.225395'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
additional_types: *7
materialized: true
delegate_hash:
id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: id
value_before_type_cast: 3feae596-a0ee-41c9-befd-c2d0fef4fd30
type: *1
organization_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: organization_id
value_before_type_cast: b4b511aa-5547-42e6-b00b-db71f7b40750
type: *1
external_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: external_id
value_before_type_cast:
type: *2
name: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: name
value_before_type_cast:
type: *2
email: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: email
value_before_type_cast:
type: *2
phone: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: phone
value_before_type_cast:
type: *2
created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: created_at
value_before_type_cast: '2016-05-25 19:24:13.225395'
type: *3
updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: updated_at
value_before_type_cast: '2016-05-25 19:24:13.225395'
type: *3
source: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: source
value_before_type_cast:
type: *2
salutation: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: salutation
value_before_type_cast:
type: *2
unsubscribed: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: unsubscribed
value_before_type_cast: f
type: *4
language: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: language
value_before_type_cast:
type: *2
country: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: country
value_before_type_cast:
type: *2
attribute1: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute1
value_before_type_cast:
type: *2
attribute2: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute2
value_before_type_cast:
type: *2
attribute3: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute3
value_before_type_cast:
type: *2
attribute4: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute4
value_before_type_cast:
type: *2
attribute5: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute5
value_before_type_cast:
type: *2
attribute6: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute6
value_before_type_cast:
type: *2
attribute7: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute7
value_before_type_cast:
type: *2
attribute8: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute8
value_before_type_cast:
type: *2
attribute9: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute9
value_before_type_cast:
type: *2
gender: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: gender
value_before_type_cast:
type: *5
attribute10: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute10
value_before_type_cast:
type: *2
new_record: false
active_record_yaml_version: 0
- !ruby/object:ExternalClient
raw_attributes:
id: a7ddaf32-2e27-4235-a76a-da0867815675
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.218848'
updated_at: '2016-05-25 19:24:13.218848'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types: *6
values:
id: a7ddaf32-2e27-4235-a76a-da0867815675
organization_id: b4b511aa-5547-42e6-b00b-db71f7b40750
external_id:
name:
email:
phone:
created_at: '2016-05-25 19:24:13.218848'
updated_at: '2016-05-25 19:24:13.218848'
source:
salutation:
unsubscribed: f
language:
country:
attribute1:
attribute2:
attribute3:
attribute4:
attribute5:
attribute6:
attribute7:
attribute8:
attribute9:
gender:
attribute10:
additional_types: *7
materialized: true
delegate_hash:
id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: id
value_before_type_cast: a7ddaf32-2e27-4235-a76a-da0867815675
type: *1
organization_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: organization_id
value_before_type_cast: b4b511aa-5547-42e6-b00b-db71f7b40750
type: *1
external_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: external_id
value_before_type_cast:
type: *2
name: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: name
value_before_type_cast:
type: *2
email: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: email
value_before_type_cast:
type: *2
phone: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: phone
value_before_type_cast:
type: *2
created_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: created_at
value_before_type_cast: '2016-05-25 19:24:13.218848'
type: *3
updated_at: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: updated_at
value_before_type_cast: '2016-05-25 19:24:13.218848'
type: *3
source: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: source
value_before_type_cast:
type: *2
salutation: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: salutation
value_before_type_cast:
type: *2
unsubscribed: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: unsubscribed
value_before_type_cast: f
type: *4
language: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: language
value_before_type_cast:
type: *2
country: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: country
value_before_type_cast:
type: *2
attribute1: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute1
value_before_type_cast:
type: *2
attribute2: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute2
value_before_type_cast:
type: *2
attribute3: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute3
value_before_type_cast:
type: *2
attribute4: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute4
value_before_type_cast:
type: *2
attribute5: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute5
value_before_type_cast:
type: *2
attribute6: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute6
value_before_type_cast:
type: *2
attribute7: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute7
value_before_type_cast:
type: *2
attribute8: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute8
value_before_type_cast:
type: *2
attribute9: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute9
value_before_type_cast:
type: *2
gender: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: gender
value_before_type_cast:
type: *5
attribute10: !ruby/object:ActiveRecord::Attribute::FromDatabase
name: attribute10
value_before_type_cast:
type: *2
new_record: false
Rather large for that small bit of JSON. It is active record stuff though which has caused a lot of problems in the past due to endless looping. That does not seem to be the case here though. There is no way I'll be able to recreate that here but maybe I can give you a debugging version that you can try. It will have to be later tonight though. Let me think about how to make that a more general feature as well. It could be useful for other in the future.
its good idea but today i have some work to do, but tomorrow i will be here :)
I checked in a version with some debugging. I can expand that as we go along. Set an environment variable OJ_DEBUG to something and run ruby extconf.rb. The run you test. You should see a bunch of dump_val printouts. That should help identify the problem area. Next I'll add more detail as we home in on the issue.
i try update gem whit
gem update oj
Updating installed gems
Nothing to update
my gemfile gem oj
any suggestions how to correct update gem ?
I do not know the following problem falls under this error but it can be also associated with it
With oj gem my code dont use json decorators (without gem is everything ok )
this is my example code
employees.rb
EmployeeViewModel.new(employee, organization!).to_json
employye_view_model.rb
class EmployeeViewModel < PersonViewModel
validates :role, inclusion: { in: [1], message: "role must be 'staff'" }
end
person_view_model.rb
class PersonViewModel
def initialize(person, organization)
@person = person
@organization = organization
end
def to_json(options={})
PersonDecorator.new(person).to_json
end
end
person_decorator.rb
class PersonDecorator < Representable::Decorator
include Representable::JSON
include Representable::Hash
property :id,
getter: ->(_){ user_id.tr('-', '') },
writeable: false
property :first_name
property :last_name,
default: nil
property :name,
getter: ->(_){ "#{first_name} #{last_name}".strip },
writeable: false
property :visible,
render_filter: lambda{ |value, _| !value.zero? },
parse_filter: lambda{ |value, _| value ? 1 : 0 },
default: 1
property :role,
render_filter: lambda{ |value, _| { 1 => 'staff', 2 => 'manager' }[value].to_s },
writeable: false
property :position
nested :image, skip_render: lambda{ |options| options[:represented].picture.nil? } do
property :picture, as: :url, writeable: false
end
property :reference,
getter: ->(_) {
user_organization = user.user_organizations.loaded? ?
user.user_organizations.select{|uo| uo.organization_id == venue.organization_id}.first :
user.user_organizations.find_by_organization_id(venue.organization_id)
user_organization.try(:external_id)
},
writeable: false
property :created_at, writeable: false
end
code start crash is ExternalClientDecorator.represent(@customers.to_a)
and use this decorator
external_client_decorator.rb
class ExternalClientDecorator < Representable::Decorator
include Representable::JSON
include Representable::Hash
property :id,
getter: lambda{ |options| id.tr('-', '') },
writeable: false
property :source,
getter: lambda{ |options| source || 'unknown' },
writeable: false
property :external_id, as: :reference
property :name
property :email
property :phone
property :created_at, writeable: false
end
finally i can reproduce crash (almost identical situation) here is code
Thanks for the code. That should help. I will try it tonight after I finish work.
I believe the problem is fixed in the release I just made.
You might consider using as_json instead of to_json. I believe to_json has been deprecated for a while.
Any feedback on the release?
hi I did not have time on weekend but tomorrow i will try a new release
everything looks fine with crash :) and i solve decorator problem with as_json
thanks again :)
Excellent. Closing the issue.
I use oj in my whole projects and everything works just fine BUT when I run a tests and try parse json response like this
with JSON.parse i got this error