Я пытаюсь написать универсальный метод для десериализации json в мою модель Моя проблема в том, что я не знаю, как получить класс из универсального типа T. Мой код выглядит примерно так (и не компилируется таким образом)
public class JsonHelper {
public <T> T Deserialize(String json)
{
Gson gson = new Gson();
return gson.fromJson(json, Class<T>);
}
}
Я пробовал что-то еще, чтобы получить тип, но он выдает ошибку. У меня был класс Нуб, которому может не хватать чего-то очевидного ...
Я пытаюсь отладить файл Rspec. На этом этапе файл Rspec урезан: Я делаю следующий вызов из командной строки: Отладчик запускается, но выдает следующую ошибку: Rspec без отладчика без проблем. Я использую Rspec 2.3.0, ruby-debug19 (0.11.6), Rails 3.0.3 и ruby 1.9.2. Почему отладчик не видит файл spec_helper? JsonHelper
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
describe "when not signed in" do
before(:each) do
get :home
end
it "should be successful" do
response.should be_success
end
it "should have a vendor section" do
response.should have_selector("h1", :content => "Vendor")
end
it "should have a hospital section" do
response.should have_selector("h1", :content => "Hospital")
end
end
end
rdebug spec/controllers/pages_controller_spec.rb
> require 'spec_helper'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/kevin/.rvm/bin/rails_projects/evaluationrx/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_load'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_program'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:412:in `<top (required)>'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/bin/rdebug:19:in `load'
/home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/bin/rdebug:19:in `<main>'
Uncaught exception: no such file to load -- spec_helper