joachimhs / Hyrrokkin

Hyrrokkin is a Java library to convert POJOs into a JSON feed that Ember Data can consume via its RESTAdapter. The name Hyrrokkin comes from Norse and means "Fire-smoked". Hyrokkin is also a dark, shrivelled giantess that helped get Balders ship Hringhorni rolled out to sea. (http://en.wikipedia.org/wiki/Hyrrokkin)
Other
15 stars 3 forks source link

Deserializer #2

Open miguelcobain opened 9 years ago

miguelcobain commented 9 years ago

Is any deserializer planned? How can we handle the task of handling the requests from Ember Data?

My main problem is how do we handle associations.

Let's say we have a POST:

{
   "user":{
      "roles":[1,2,3,4]
   }
}

and

public class User {
    List<Role> roles;
}

What would be the equivalent instance in Java? Creating Role instances within a User instance, with only the their id set? Seems the most sensible approach.

joachimhs commented 9 years ago

I am working on a deserialiser, but I haven't got one up to commit-quality as of yet. The problem is, as you say, with associations.

I think the best viable option is to do the opposite of the serialiser, meaning to take the flat structure of the JSON and build a hierarchical instead.

Then once this structure is OK, a simple new Gson().fromJson(jsonString, MyClass.class) would suffice (in an internal private method inside Hyrrokkin)

Hashtables all the way :)