I have a hash that looks like:
require 'json'
h = { :foo => 1, :bar => 1 }
h.to_json # will do '{ "foo" : 1, "bar" 1 }'
The best way I've found is to rekey and serialize: https://stackoverflow.com/a/4137966/887836
In java there is an annotation to rename "foo" into "Foo" to have a specific serialized view. Is there a standard way of doing this in ruby? I'd prefer a declarative way of specifying this if that's available.
public class MyClass {
@SerializedName("Foo") String foo;
public MyClass(String foo) {
this.foo = foo;
}
}