Simple Deserialization utility in Ruby.


(Vineel Yalamarthi) #1

Hi Guys

I'm new to Ruby and wondering if there is a deserialization utility in
Ruby similar to Java's Google GSON library.

When we use Google GSON, there is no need to define custom deserializer or
define in the model class that we want this to be serializable etc.

I posted more details here:

For instance, in Java using Google GSON, we can accomplish conversion of
String (Json object) to custom Java object .

*Address address=gson.fromJson(addressJsonStringForm, Address.class);*
Thanks in advance.

Regards
Vineel


(Walter Lee Davis) #2

Have you tried JSON.parse for this?

Walter

···

On Dec 22, 2018, at 4:18 PM, Vineel Yalamarthi <vineelyalamarthi@gmail.com> wrote:

Hi Guys

I'm new to Ruby and wondering if there is a deserialization utility in Ruby similar to Java's Google GSON library.

When we use Google GSON, there is no need to define custom deserializer or define in the model class that we want this to be serializable etc.

I posted more details here:
https://stackoverflow.com/questions/53899249/json-deserialization-in-ruby

For instance, in Java using Google GSON, we can accomplish conversion of String (Json object) to custom Java object .

Address address=gson.fromJson(addressJsonStringForm, Address.class);

Thanks in advance.

Regards
Vineel

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


(Marvin Gülker) #3

There are a number of serialisers/deserialisers available actually:

* Marshal, in core: https://ruby-doc.org/core-2.5.3/Marshal.html
* YAML, in the stdlib: https://ruby-doc.org/stdlib-2.5.3/libdoc/yaml/rdoc/YAML.html
* JSON, in the stdlib: https://ruby-doc.org/stdlib-2.5.3/libdoc/json/rdoc/JSON.html

Marshal and YAML can directly (de)serialise Ruby objects, within certain
restrictions. For instance, you cannot serialise File instances as they
refer to an open file descriptor under the hood.

Marvin

···

Am 22. Dezember 2018 um 13:18 Uhr -0800 schrieb Vineel Yalamarthi:

Hi Guys

I'm new to Ruby and wondering if there is a deserialization utility in
Ruby similar to Java's Google GSON library.

--
Blog: https://mg.guelker.eu
PGP/GPG ID: F1D8799FBCC8BC4F