Hi guys,
The JSON extension that we propose does have some limitations. I'd like to
offer a stronger alternative in the future but I'm not
sure yet which library is the best.
JSON-Lib is richer and stable but lacks streaming parser which might be
important for larger documents and more responsive dynamic
resources. I've been looking at a new Jackson project which looks promising:
"Alternative JSON support"
http://restlet.tigris.org/issues/show_bug.cgi?id=656
Otherwise, using JSON-Lib directly should be easy. Just write a subclass like
this:
public class JsonLibRepresentation extends WriterRepresentation {
// JSON value to serialize
net.sf.json.JSON json;
public JsonLibRepresentation(net.sf.json.JSON json){
super(MediaType.APPLICATION_JSON);
setCharacterSet(CharacterSet.UTF_8);
this.json = json;
}
@Override
public void write(Writer writer) throws IOException{
json.write(writer);
}
}
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
-Message d'origine-
De : news [mailto:n...@ger.gmane.org] De la part de Evgeny Shepelyuk
Envoye : lundi 12 janvier 2009 10:04
A : discuss@restlet.tigris.org
Objet : Re: JSON-Lib and Restlet
Hi
+1 on this queistion.
Some time ago personally i asked the same question. But we still don't
have impelmentaiton :)
Maybe you can produce it ?
In my projects i've been usign StringRepresentaion and other 'hacks' to
produce output
using Json-lib and not internal Restlet JSON support.
> I am a new user of Restlet (and quite hapy with it, too), but I found
> that using the JSON classes that come with it do not work well enough
> for me. They do serialize basic classes, but do not work on things like
> HashMap, or really anything nested. I checked the main JSON website to
> see if there were newer versions of those classes (there are), but they
> still do not on nested objects.
>
> JSON-Lib does work well for this, so I switched to using that. However,
> when I want to create a representation out of the new (JSON-Lib)
> JSONObject, it does not accept the type.
>
>Representation representation = new JsonRepresentation(json);
>
> The warning is: "Type safety: The expression of type JSONObject needs
> unchecked conversion to conform to Map"
>
> The reason is because "json" is of type "net.sf.json.JSONObject" instead
> of "org.json.JSONObject". Ultimately, the best solution is for
> "net.sf.json.JSONObject" to extend "org.json.JSONObject", as is done
> with other JSON libraries I have tested, but I seriously doubt this is
> going to happen. I can "fix" the issue by doing this instead:
>
>Representation representation = new
> JsonRepresentation(json.toString());
>
> It just seems wasteful to have a usable JSONObject, convert it to a
> string and then pass it to a constructor.
>
> Has anyone successfully used JSON-Lib with Restlet without resorting to
> a hack like this? Also, is there a reason that Restlet only works with
> the basic "org.json.*" library? I would think that JSONObject should be
> handled in the way logging is handled: you can use the basic built-in
> logging in the JDK, or use something else, like Log4J. Can this also be
> done with "org.json.*" and other JSON implementations, too?
>
> I very much would appreciate any replies / suggestions.
>
> Mike V.
>
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1014233
>
--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1018641
--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1023920