Today I Learned

Singleton can't be dumped error

when passing an array of objects to a serializer, I’ve received an error which stated: Singleton can't be dumped. To fix the issue I’ve created a presenter for a singleton object:

  class StateTransitionPresenter
    attr_reader :state_transition

    def initialize(state_transition)
      @state_transition = state_transition

    def as_json(options = {})
        state_transition_time: state_transition.time,
        state: state_transition.state,
        reason: state_transition.reason

and then I used it in the serializer:{ |state_transition|}.as_json