#<NoMethodError: undefined method `encode' for OpenStruct:Class>

Open
#60 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
ruby
Domain
backend

Research direction

Start by reproducing the JSON.parse call with object_class: OpenStruct and read the OpenStruct implementation involved in the error. Compare the reported NoMethodError with the expected Routeguide::Point-style object; the issue is resolved when the cause and expected parsing behavior are established.

Written by the indexing model from the issue text.

Description

I am getting the below error when trying to parse a json object into class object.

#<NoMethodError: undefined method `encode' for OpenStruct:Class>

Code I am using:

# json_string = {"latitude":409146138,"longitude":124678384}
object = JSON.parse(json_string, object_class: OpenStruct)

Target Object looks like this:
<Routeguide::Point: latitude: 409146138, longitude: -746188906>

Dominant language
Ruby
Stars
175
Forks
35
Avg merge
16h 14m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/ostruct

All issues in ruby/ostruct

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.