Closed mb720 closed 8 years ago
That's a typical JavaScript issue. When parsing the JSON, all you get are the data parts of the objects, not the actual instances. In order to get the instances, you need to "revive" your data objects. Here is a JSweet function to revive your objects to articles implemented with jQuery:
import static def.jquery.Globals.$;
[...]
private Article revive(Object untypedDto) {
return (Article) $.extend(new Article(), untypedDto);
}
You need to call it on each article object after it has been parsed from JSON.
Note that it is possible to have a more transparent solution but it requires to have a type metadata in your objects.
Hi!
My server sends a
List<Article>
to the client whereArticle
is a custom datatype of mine that contains the methodgetName()
.Now, I convert those
Article
s to JSON on the server side using Gson:On the client side, I get the
Article
s as a JSON string like this:I call it to get the JSON and convert it to
Article
objects.Everything compiles just fine but unfortunately although
toArticles
type checks, it doesn't really returnArticle
s since I getTypeError: article.getName is not a function
when callingarticle.getName()
.Any help is appreciated.